Lingering Subinterpreter Subthread Keeps Program From Exiting #113146
Labels
3.12
only security fixes
3.13
bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-subinterpreters
type-bug
An unexpected behavior, bug, or error
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Steps:
One would expect execution to flow as follows:
main thread
main thread
subthread
However, that isn't what's happening. Instead, at some point the subthread stops executing (without error) and the process effectively hangs (but can be stopped with Ctrl-C).
Script:
Expected output:
Expected output:
I'm fairly sure I know what the problem is: our hack for dealing with daemon threads. Currently, between steps 8 and 9 above, we mark the runtime as finalizing. Any threads (regardless of interpreter) are more or less immediately killed.
However, as far as the threading module is concerned, they are still valid and running and will never stop. This isn't a problem for the main interpreter because at that point it already waited for it's own non-daemon threads to finish.
This is a problem for subinterpreters because they don't wait for their non-daemon threads to finish until later. Thus we end up waiting forever at step 10.
The solution? Immediately after waiting for non-daemon threads in step 8, finalize all subinterpreters. Alternately, we could make sure we're only killing daemon threads with our hack (e.g. don't use a global "finalizing" check).
The text was updated successfully, but these errors were encountered: