This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aeros
Recipients aeros, eric.snow, vstinner
Date 2019-12-01.04:23:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1575174189.52.0.427280357232.issue37224@roundup.psfhosted.org>
In-reply-to
Content
> Regarding "is_running()", notice that it relies almost entirely on "frame->f_executing".  That might not be enough (or maybe the behavior there changed).  That would be worth checking out.

Based on the above hint, I was able to make some progress on a potential solution. Thanks Eric.

Instead of only checking "frame->f_executing", I changed "_is_running()" to also check the "finalizing" field of PyInterpreterState. The "finalizing" field is set to 1 in "Py_EndInterpreter()", so this ensures that an interpreter in the process of being destroyed is considered "running", so that operations (such as running scripts, destroying the interpreter, etc) can't occur during finalization. I had to add a private function to the C-API in order to access "interp->finalizing" from Modules/_xxsubinterpretersmodule.c due to the struct for PyInterpreterState being internal only.

The above fix seems to completely remove the test failure that occurs in "interpreters.destroy(interp)" in "test_already_running" after running it several times, but I'm able to consistently reproduce the following:

Exception in thread Thread-8:
Traceback (most recent call last):
  File "/home/aeros/repos/aeros-cpython/Lib/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/home/aeros/repos/aeros-cpython/Lib/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/aeros/repos/aeros-cpython/Lib/test/test__xxsubinterpreters.py", line 51, in run
    interpreters.run_string(interp, dedent(f"""
RuntimeError: unrecognized interpreter ID 46
test test__xxsubinterpreters failed -- Traceback (most recent call last):
  File "/home/aeros/repos/aeros-cpython/Lib/test/test__xxsubinterpreters.py", line 492, in test_subinterpreter
    self.assertTrue(interpreters.is_running(interp))
AssertionError: False is not true

I have a few ideas that I'd like to test out for fixing this failure, and if any of them produce positive results I'll report back. Since the failures are still consistently occurring, I have not yer revised GH-16293. I'll do that when/if I come up with a more thorough solution.
History
Date User Action Args
2019-12-01 04:23:09aerossetrecipients: + aeros, vstinner, eric.snow
2019-12-01 04:23:09aerossetmessageid: <1575174189.52.0.427280357232.issue37224@roundup.psfhosted.org>
2019-12-01 04:23:09aeroslinkissue37224 messages
2019-12-01 04:23:08aeroscreate