-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-123940: Ensure force-terminated daemon threads can be joined #124150
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
04c6803
679ce7d
4d02a0b
cd7b7d1
bf186e2
96613ed
d18c872
33ab654
192b260
57a1c65
aa1039a
3978cc0
5991fa4
9a94905
512b5fc
70f28c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1171,6 +1171,41 @@ def __del__(self): | |
self.assertEqual(out.strip(), b"OK") | ||
self.assertIn(b"can't create new thread at interpreter shutdown", err) | ||
|
||
@unittest.skipIf(support.Py_GIL_DISABLED, "gh-124149: daemon threads don't force exit") | ||
def test_join_force_terminated_daemon_thread_in_finalization(self): | ||
# gh-123940: Py_Finalize() forces all daemon threads to exit | ||
# immediately (without unwinding the stack) upon acquiring the | ||
# GIL. Finalizers that run after this must be able to join the daemon | ||
# threads that were forced to exit. | ||
code = textwrap.dedent(""" | ||
import threading | ||
|
||
|
||
def loop(): | ||
while True: | ||
pass | ||
Comment on lines
+1184
to
+1186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A slight variant where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly #87135 related. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the issue #116514 colesbury linked when I asked (I wasn't able to repro just the time.sleep variant mentioned here) |
||
|
||
|
||
class Cycle: | ||
def __init__(self): | ||
self.self_ref = self | ||
self.thr = threading.Thread(target=loop, daemon=True) | ||
self.thr.start() | ||
|
||
def __del__(self): | ||
self.thr.join() | ||
mpage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print('__del__ called') | ||
|
||
# Cycle holds a reference to itself, which ensures it is cleaned | ||
# up during the GC that runs after daemon threads have been | ||
# forced to exit during finalization. | ||
Cycle() | ||
""") | ||
rc, out, err = assert_python_ok("-c", code) | ||
self.assertEqual(err, b"") | ||
self.assertIn(b"__del__ called", out) | ||
|
||
|
||
class ThreadJoinOnShutdown(BaseTestCase): | ||
|
||
def _run_and_join(self, script): | ||
|
Uh oh!
There was an error while loading. Please reload this page.