Skip to content

[WIP] bpo-40068: test_reinit_tls_after_fork() detects crashes #19200

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,18 @@ def test_reinit_tls_after_fork(self):
# Issue #13817: fork() would deadlock in a multithreaded program with
# the ad-hoc TLS implementation.

all_status = []

def do_fork_and_wait():
# just fork a child process and wait it
pid = os.fork()
if pid > 0:
os.waitpid(pid, 0)
else:
if not pid:
# child process: just exit
os._exit(0)

pid, status = os.waitpid(pid, 0)
all_status.append(status)

# start a bunch of threads that will fork() child processes
threads = []
for i in range(16):
Expand All @@ -915,6 +919,10 @@ def do_fork_and_wait():
for t in threads:
t.join()

# ensure that all child processes completed successfully (no crash)
for status in all_status:
self.assertEqual(status, 0)

@unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()")
def test_clear_threads_states_after_fork(self):
# Issue #17094: check that threads states are cleared after fork()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_reinit_tls_after_fork() of test_threading now checks if a child process
crashed in os.fork().