Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7242] Forking in a thread raises RuntimeError

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Oct 30, 2009, 3:58 AM

Post #1 of 8 (425 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError

New submission from Zsolt Cserna <zsolt.cserna [at] morganstanley>:

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.

----------
components: Library (Lib)
files: thread_test.py
messages: 94701
nosy: csernazs
severity: normal
status: open
title: Forking in a thread raises RuntimeError
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file15232/thread_test.py

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 30, 2009, 4:06 AM

Post #2 of 8 (392 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

Well, there has been no such change between 2.6.3 and 2.6.4.

----------
nosy: +gregory.p.smith, pitrou

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 30, 2009, 4:41 AM

Post #3 of 8 (391 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Zsolt Cserna <zsolt.cserna [at] morganstanley> added the comment:

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).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 31, 2009, 12:50 PM

Post #4 of 8 (366 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Gregory P. Smith <greg [at] krypto> added the comment:

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.

----------
assignee: -> gregory.p.smith
nosy: +twouters
priority: -> normal
versions: +Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 12:31 AM

Post #5 of 8 (350 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Zsolt Cserna <zsolt.cserna [at] morganstanley> added the comment:

I've tested it only on solaris 8, 32-bit.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 1:44 AM

Post #6 of 8 (350 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Zsolt Cserna <zsolt.cserna [at] morganstanley> added the comment:

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.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 7:51 AM

Post #7 of 8 (348 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Zsolt Cserna <zsolt.cserna [at] morganstanley> added the comment:

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.

----------
keywords: +patch
Added file: http://bugs.python.org/file15247/patch_1.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 9, 2009, 4:38 AM

Post #8 of 8 (290 views)
Permalink
[issue7242] Forking in a thread raises RuntimeError [In reply to]

Zsolt Cserna <zsolt.cserna [at] morganstanley> added the comment:

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.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.