-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Subinterpreters don't properly clean up threads #128639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
FWIW, I thought I had created an issue about cleaning up lingering thread states automatically. Would you mind double-checking and closing it, if so? |
…-128640) Incidentally, this also fixed the warning not showing up if a subinterpreter wasn't cleaned up via _interpreters.destroy. I had to update some of the tests as a result.
…on (pythongh-128640) Incidentally, this also fixed the warning not showing up if a subinterpreter wasn't cleaned up via _interpreters.destroy. I had to update some of the tests as a result. (cherry picked from commit 9859791) Co-authored-by: Peter Bierma <[email protected]>
…nalization (pythongh-128640)" This reverts commit 9859791.
For those who aren't me or Eric: we had to revert the fix because it breaks the test suite when run with |
@ericsnowcurrently I finally figured out the buildbot failures. This is an awesome bug. Here's a repro that crashes with my patch applied: import _interpreters
import types
import time
interp = _interpreters.create(
types.SimpleNamespace(
use_main_obmalloc=False,
allow_fork=False,
allow_exec=False,
allow_threads=True,
allow_daemon_threads=True,
check_multi_interp_extensions=True,
gil='own',
)
)
_interpreters.exec(interp, f"""if True:
import threading
import time
def task():
time.sleep(1)
threads = [threading.Thread(target=task, daemon=True) for _ in range(3)]
for t in threads:
t.start()
""")
_interpreters.destroy(interp)
time.sleep(2) The problem is that something subtly changed with daemon thread shutdown in-between writing my patch and merging it. So, after the |
…inalization (pythongh-128640)" (pythongh-134256) This reverts commit 27bd082.
Uh oh!
There was an error while loading. Please reload this page.
Crash report
What happened?
I found this issue a little while back, but I'm finally getting around to fixing it.
Currently, subinterpreter finalization assumes that there's only one thread left. So, any remaining threads--daemon or non-daemon--crash the interpreter upon finalizing:
This results in an assertion failure on my end:
So, there's a few things that need to get fixed:
Py_EndInterpreter
, which will properly clean things up.PyThreadState_Delete
. That should also happen inPy_EndInterpreter
, after all threads have finished._PyRuntimeState_SetFinalizing
has been set, meaning that all threads will be already blocked, and thus cannot shutdown viathreading._shutdown
, resulting in a deadlock.finalize_subinterpreters
should be called before that happens.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: