Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
GH-110829: Ensure Thread.join() joins the OS thread#110848
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4074b5927ae38b31bf2f3192a741e9c1e7a70a6855d61fd5e751675e235544e1a58a2447809e870d3e51d14db2699f3f525a909ca420ece696849d15cf2684fa11244File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -376,16 +376,16 @@ def test_limbo_cleanup(self): | ||
| # Issue 7481: Failure to start thread should cleanup the limbo map. | ||
| def fail_new_thread(*args): | ||
| raise threading.ThreadError() | ||
| _start_new_thread = threading._start_new_thread | ||
| threading._start_new_thread = fail_new_thread | ||
| _start_joinable_thread = threading._start_joinable_thread | ||
| threading._start_joinable_thread = fail_new_thread | ||
| try: | ||
| t = threading.Thread(target=lambda: None) | ||
| self.assertRaises(threading.ThreadError, t.start) | ||
| self.assertFalse( | ||
| t in threading._limbo, | ||
| "Failed to cleanup _limbo map on failure of Thread.start().") | ||
| finally: | ||
| threading._start_new_thread = _start_new_thread | ||
| threading._start_joinable_thread = _start_joinable_thread | ||
| def test_finalize_running_thread(self): | ||
| # Issue 1402: the PyGILState_Ensure / _Release functions may be called | ||
| @@ -482,6 +482,47 @@ def test_enumerate_after_join(self): | ||
| finally: | ||
| sys.setswitchinterval(old_interval) | ||
| def test_join_from_multiple_threads(self): | ||
gpshead marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Thread.join() should be thread-safe | ||
| errors = [] | ||
| def worker(): | ||
| time.sleep(0.005) | ||
| def joiner(thread): | ||
| try: | ||
| thread.join() | ||
| except Exception as e: | ||
| errors.append(e) | ||
| for N in range(2, 20): | ||
| threads = [threading.Thread(target=worker)] | ||
| for i in range(N): | ||
| threads.append(threading.Thread(target=joiner, | ||
| args=(threads[0],))) | ||
| for t in threads: | ||
| t.start() | ||
| time.sleep(0.01) | ||
| for t in threads: | ||
| t.join() | ||
| if errors: | ||
| raise errors[0] | ||
ericsnowcurrently marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_join_with_timeout(self): | ||
gpshead marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| lock = _thread.allocate_lock() | ||
| lock.acquire() | ||
| def worker(): | ||
| lock.acquire() | ||
| thread = threading.Thread(target=worker) | ||
| thread.start() | ||
| thread.join(timeout=0.01) | ||
| assert thread.is_alive() | ||
| lock.release() | ||
| thread.join() | ||
| assert not thread.is_alive() | ||
| def test_no_refcycle_through_target(self): | ||
| class RunSelfFunction(object): | ||
| def __init__(self, should_raise): | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the changes in this file are probably not necessary, it's just that without them the threads emulation of processes takes a very long time to test. The reason is simple and not related to this PR: while you can terminate a process early, you cannot do that on a thread, so joining a sleeping thread has to wait for the sleep to finish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use a shorter wait time rather than skip the test entirely: #114186