This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: threads duplicated on fork() prevent child from terminating
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, imbaczek, wotevah
Priority: normal Keywords:

Created on 2004-07-19 18:59 by wotevah, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
threads_duplicated_on_fork.py wotevah, 2004-07-19 18:59 Test code
Messages (3)
msg21686 - (view) Author: L.C. (Laurentiu C. Badea) (wotevah) Date: 2004-07-19 18:59
(This is a repost from an older c.l.py submission to
prevent losing track of it)

It looks as if fork() duplicates the entire threads
info structure in the new process. This causes child
processes to attempt to handle or wait for nonexistent
threads and causes them to hang on exit.

Perhaps clearing Python's internal thread info after
the fork() is all that is needed to fix this (the fact
that the threads themselves are not duplicated  seems
to suggest that this was indeed the intention - and
also is POSIXly correct).

Original post with sample code for the problem is here
(also attached for your convenience):

0306191548.73b7383%40posting.google.com">http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=e0bf36b5.0306191548.73b7383%40posting.google.com

The "bug" manifests itself by the program not exiting
voluntarily. The two processes created need to be
terminated individually.

Last tested on 2.3.3 (Fedora Core 2), but present since
2.1 I believe.
msg21687 - (view) Author: Marek Baczynski (imbaczek) Date: 2007-06-05 18:00
Just ran into this in 2.5 on debian testing. Workaround is to setDaemon(True) on the offending threads; this is not documented anywhere, though.
msg81507 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-09 22:10
Test case works for me with trunk and py3k (rev. 69469) on Linux 2.6.24
ia32.
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40597
2009-02-10 02:10:39benjamin.petersonsetstatus: open -> closed
resolution: out of date
2009-02-09 22:10:13ajaksu2setnosy: + ajaksu2
messages: + msg81507
2004-07-19 18:59:07wotevahcreate