Message113643
Importing the module with the following contents results in RuntimeError:
==================
import os
pid = os.fork()
if pid == 0:
print "In the child"
else:
print "In the parent"
print "Done\n"
==================
Running the same module as main works just fine, so it seems to be a purely import issue.
I looked into the 2.6.6rc1 source. This is what I think happens in Python/import.c file:
1. After the fork() call, _PyImport_ReInitLock() is run. It sets import_lock_thread to -1 in the child, line 310.
2. In _PyImport_ReleaseLock() line 290 compares import_loc_thread to the current thread id, and if they are not the same then -1 is returned, which results in RuntimeError in PyImport_ImportModuleLevel (line 2186-2189)
So this is guaranteed to happen in the child, every time fork() is executed inside the module being imported. If I change line 290 to be:
if (import_lock_thread != me && import_lock_thread != -1)
then import proceeds fine, although I'm not sure this is a proper solution.
This happens on Linux, Darwin, and Cygwin, with python 2.6.5 and higher. I'd be happy to assist solving this, please let me know how I can help. |
|
Date |
User |
Action |
Args |
2010-08-11 23:42:05 | Alex.Roitman | set | recipients:
+ Alex.Roitman |
2010-08-11 23:42:04 | Alex.Roitman | set | messageid: <1281570124.9.0.596338600617.issue9573@psf.upfronthosting.co.za> |
2010-08-11 23:42:02 | Alex.Roitman | link | issue9573 messages |
2010-08-11 23:42:01 | Alex.Roitman | create | |
|