[Python-Dev] pthreads, fork, import, and execvp

Ronald Oussoren ronaldoussoren at mac.com
Thu May 18 17:18:05 CEST 2006


On 16-mei-2006, at 23:20, Martin v. Löwis wrote:

> Nick Coghlan wrote:
>> Broadening the ifdef to cover all posix systems rather than just AIX
>> might be the right thing to do.
>
> As I said: I doubt it is the right thing to do. Instead, the lock
> should get released in the child process if it is held at the
> point of the fork.
>
> I agree that we should find a repeatable test case first.
> Contributions are welcome.

 From what I understand the problem is that when a thread other than  
the thread calling fork is holding the import lock the child process  
ends up with an import lock that is locked by a no longer existing  
thread.

The attached script reproduces the problem for me. This creates a  
thread to imports a module and a thread that forks. Run  
'forkimport.py' to demonstrate the problem, if you set 'gHang' at the  
start of the script to 0 the child process doesn't perform an import  
and terminates normally.

Wouldn't this specific problem be fixed if os.fork were to acquire  
the import lock before calling fork(2)?

Ronald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: forklock.tgz
Type: application/octet-stream
Size: 544 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20060518/cfd0407e/attachment.obj 
-------------- next part --------------


>
> Regards,
> Martin
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/ 
> ronaldoussoren%40mac.com



More information about the Python-Dev mailing list