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 csernazs
Recipients csernazs
Date 2009-10-30.10:57:59
SpamBayes Score 5.04161e-10
Marked as misclassified No
Message-id <>
Python 2.6.4 (r264:75706, Oct 29 2009, 12:00:12) [C] on sunos5

On my sunos5 system if I call os.fork() in a thread created by
thread.start_new_thread(), it raises RuntimeError with the message 'not
holding the import lock'. It's a vanilla python compiled on sunos5 with
suncc. In 2.6.3 it's ok, I think this issue is caused by patch located

The problem can be re-produced by running the script attached.

I've looked into the source and it seems to me the following:

Based on the the change above, it calls fork1() system call between a
lock-release calls:

3635 » _PyImport_AcquireLock();
3636 » pid = fork1();
3637 » result = _PyImport_ReleaseLock();

_PyImport_ReleaseLock is called in both the child and parent. Digging
more into the code, _PyImport_ReleaseLock starts with the following:

        long me = PyThread_get_thread_ident();
        if (me == -1 || import_lock == NULL)
                return 0; /* Too bad */
        if (import_lock_thread != me)
                return -1;

In the above code, if I interpret correctly, it compares the result of
the current thread id returned by PyThread_get_thread_ident call with
the thread id of the thread holding the lock - if it's different then
the current thread cannot release the lock because it's not owned by it.

Based on my results on solaris the 'me' variable will be different in
the parent and in the child (in parent it remains the same) - resulting
that the child thinks that it's not holding the release lock.

I'm using pthreads on both linux and solaris. On linux the code above is
working fine, but on solaris it behaves differently.
Date User Action Args
2009-10-30 10:58:03csernazssetrecipients: + csernazs
2009-10-30 10:58:02csernazssetmessageid: <>
2009-10-30 10:58:01csernazslinkissue7242 messages
2009-10-30 10:57:59csernazscreate