[Python-Dev] pthreads, fork, import, and execvp
"Martin v. Löwis"
martin at v.loewis.de
Thu May 18 20:02:06 CEST 2006
Nick Coghlan wrote:
> And if I understand it correctly, it falls under the category that
> waiting for another thread while holding the import lock is a *really*
> bad idea from a thread safety point of view.
>
> The thing with the import-after-fork deadlock is that you can trigger it
> without even doing anything that's known not to be thread-safe.
Right. With some googling, I found that one solution is pthread_atexit:
a pthread_atexit handler is a triple (before, in_parent, in_child).
You set it to (acquire, release, release). When somebody forks,
the pthread library will first acquire the import lock in the thread
that wants to fork. Then the fork occurs, and the import lock gets
then released both in the parent and in the child.
I would like to see this approach implemented, but I agree with you
that a test case should be created first.
Regards,
Martin
More information about the Python-Dev
mailing list