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.

Author neologix
Recipients Giovanni.Bajo, avian, bobbyi, gregory.p.smith, neologix, nirai, pitrou, sdaoden, vstinner
Date 2011-07-05.11:47:11
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <CAH_1eM2SKXifR_uFXCuTW2ptAtbircuDA+R36R973bvMYJOf3g@mail.gmail.com>
In-reply-to <1309864842.21.0.629203178239.issue6721@psf.upfronthosting.co.za>
Content
> Except for multiprocessing, does anyone know of any other module in the standard library that uses fork() and threads at the
> same time? After some grepping through the source I couldn't find any other cases.

The same problem arises in case of user-created threads, this problem
is not specific to the multiprocessing.

> Just to clarify: it's not that POSIX atfork() handlers run from signal handlers. It's that after a fork in a multithreaded process POSIX only guarantees calls to "safe" functions, which is the same set of functions as those that are safe to call from signal handlers. This fact does not change for Python's os.fork().
>

I think Nir knows perfectly that, he was just referring to a
limitation of pthread_atfork:
- fork() is async-safe, and thus can be called from a signal handler
- but if pthread_atfork handlers are installed, then fork() can become
non async-safe, if the handlers are not async-safe (and it's the case
when you're dealing with POSIX mutexes for example)
But since Python's user-defined signal handlers are actually called
synchronously (and don't run on behalf of the signal handler), there's
no risk of fork() being called from a signal handler.

> I'm still in favor of just deprecating using fork() on a multithreaded process (with appropriate warnings and documentation)

We can't do that, it would break existing code.
Furthermore, some libraries use threads behind the scene.

> I'm prepared to work on a patch that would remove the need for helper threads in the multiprocessing module.

What do you mean by helper threads?
History
Date User Action Args
2011-07-05 11:47:12neologixsetrecipients: + neologix, gregory.p.smith, pitrou, vstinner, nirai, bobbyi, Giovanni.Bajo, sdaoden, avian
2011-07-05 11:47:12neologixlinkissue6721 messages
2011-07-05 11:47:11neologixcreate