Skip to content

test_3_join_in_forked_from_thread forks (and starts thread) at shutdown #116612

Open
@colesbury

Description

@colesbury

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions