Issue7242
Created on 2009-10-30 10:58 by csernazs, last changed 2009-11-09 12:38 by csernazs.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
thread_test.py
|
csernazs,
2009-10-30 10:57
|
A test demonstrating the issue. |
|
|
|
patch_1.diff
|
csernazs,
2009-11-02 15:51
|
A possible fix for this issue created for python 2.6.4. |
|
|
|
msg94701 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-10-30 10:57 |
|
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
at http://codereview.appspot.com/96125/show.
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.
|
|
msg94702 - (view) |
Author: Antoine Pitrou (pitrou) |
Date: 2009-10-30 11:06 |
|
Well, there has been no such change between 2.6.3 and 2.6.4.
|
|
msg94704 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-10-30 11:41 |
|
Sorry, the working version is not 2.6.3 (I mistyped the version), it's
2.6.1 (I've no info about 2.6.2).
|
|
msg94765 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-10-31 19:50 |
|
This only appears to happen on Solaris. What version of Solaris are you
using? (i doubt that matters, i expect it happens on all versions)
I haven't look closely enough at the code yet, but reinitializing the
import lock in the child process should make sense here.
|
|
msg94820 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-11-02 08:31 |
|
I've tested it only on solaris 8, 32-bit.
|
|
msg94822 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-11-02 09:44 |
|
solaris 10 x86, 32-bit, sun-studio 11 is ok (in this case the parent's
thread has thread_id=2 and the child inherits this id)
solaris 8 sparc4, 32-bit, sun-studio 11 is not working
So it seems it's independent from sun-cc but depends from the
architecture and/or the OS.
|
|
msg94832 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-11-02 15:51 |
|
I've attached a patch which seems to fix this issue. It sets
import_lock_thread to the current thread id after forking in the child
process, but still I'm not quite sure that it's the correct way of
solving this issue.
|
|
msg95075 - (view) |
Author: Zsolt Cserna (csernazs) |
Date: 2009-11-09 12:38 |
|
Additional info:
I've tested it on solaris 10 / sparc 32-bit, and my test script runs
fine on that.
Based on my test it seems that this bug does not affect solaris 10.
|
|
| Date |
User |
Action |
Args |
| 2009-11-09 12:38:08 | csernazs | set | messages:
+ msg95075 |
| 2009-11-02 15:51:54 | csernazs | set | files:
+ patch_1.diff keywords:
+ patch messages:
+ msg94832
|
| 2009-11-02 09:44:50 | csernazs | set | messages:
+ msg94822 |
| 2009-11-02 08:31:13 | csernazs | set | messages:
+ msg94820 |
| 2009-10-31 19:50:03 | gregory.p.smith | set | priority: normal versions:
+ Python 3.1, Python 2.7, Python 3.2 nosy:
+ twouters
messages:
+ msg94765
assignee: gregory.p.smith |
| 2009-10-30 11:41:27 | csernazs | set | messages:
+ msg94704 |
| 2009-10-30 11:06:41 | pitrou | set | nosy:
+ gregory.p.smith, pitrou messages:
+ msg94702
|
| 2009-10-30 10:58:01 | csernazs | create | |
|