Skip to content

test_3_join_in_forked_from_thread forks (and starts thread) at shutdown #116612

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

Open
colesbury opened this issue Mar 11, 2024 · 1 comment
Open
Labels
tests Tests in the Lib/test dir topic-free-threading

Comments

@colesbury
Copy link
Contributor

colesbury commented Mar 11, 2024

The test_3_join_in_forked_from_thread test case in test_threading.py may call fork during shutdown:

@skip_unless_reliable_fork
def test_3_join_in_forked_from_thread(self):
# Like the test above, but fork() was called from a worker thread

The relevant code looks like:

def worker():
    childpid = os.fork()
    ...

w = threading.Thread(target=worker)
w.start()

The interpreter starts shutting down immediately after w.start(). In the default build, this is usually OK because the GIL switching interval (and limited eval breaker checks) means that the os.fork() call likely happens before the w.start() returns, but there is no guarantee of that. In the free-threaded build, this is much more likely to raise a PythonFinalizationError: can't fork at interpreter shutdown error because the w.start() call returns more quickly.

See also #114570

@colesbury colesbury added tests Tests in the Lib/test dir topic-free-threading labels Mar 11, 2024
@colesbury
Copy link
Contributor Author

You can reliably trigger the problem by adding a time.sleep(0.1) immediately before the childpid = os.fork().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir topic-free-threading
Projects
None yet
Development

No branches or pull requests

1 participant