mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] gh-113964: Don't prevent new threads until all non-daemon threads exit (GH-116677) (#117029)
Starting in Python 3.12, we prevented calling fork() and starting new threads
during interpreter finalization (shutdown). This has led to a number of
regressions and flaky tests. We should not prevent starting new threads
(or `fork()`) until all non-daemon threads exit and finalization starts in
earnest.
This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`,
which is set immediately before terminating non-daemon threads.
(cherry picked from commit 60e105c1c1
)
This commit is contained in:
parent
4be9fa8961
commit
92564331de
8 changed files with 57 additions and 27 deletions
|
@ -3413,14 +3413,15 @@ class POSIXProcessTestCase(BaseTestCase):
|
|||
def dummy():
|
||||
pass
|
||||
|
||||
def exit_handler():
|
||||
subprocess.Popen({ZERO_RETURN_CMD}, preexec_fn=dummy)
|
||||
print("shouldn't be printed")
|
||||
|
||||
atexit.register(exit_handler)
|
||||
class AtFinalization:
|
||||
def __del__(self):
|
||||
print("OK")
|
||||
subprocess.Popen({ZERO_RETURN_CMD}, preexec_fn=dummy)
|
||||
print("shouldn't be printed")
|
||||
at_finalization = AtFinalization()
|
||||
"""
|
||||
_, out, err = assert_python_ok("-c", code)
|
||||
self.assertEqual(out, b'')
|
||||
self.assertEqual(out.strip(), b"OK")
|
||||
self.assertIn(b"preexec_fn not supported at interpreter shutdown", err)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue