[Python-Dev] fun threading problem
Neal Norwitz
nnorwitz at gmail.com
Thu Sep 14 09:48:57 CEST 2006
On everyones favorite platform (HP-UX), the following code consistently fails:
###
from thread import start_new_thread, allocate_lock
from time import sleep
def bootstrap():
from os import fork ; fork()
allocate_lock().acquire()
start_new_thread(bootstrap, ())
sleep(.1)
###
The error is:
Fatal Python error: Invalid thread state for this thread
This code was whittled down from test_socketserver which fails in the
same way. It doesn't matter what value is passed to sleep as long as
it's greater than 0. I also tried changing the sleep to a while 1:
pass and the same problem occurred. So there isn't a huge interaction
of APIs, only: fork, allocate_lock.acquire and start_new_thread.
HP-UX seems to be more sensitive to various threading issues. In
Modules/_test_capimodule.c, I had to make this modification:
Index: Modules/_testcapimodule.c
===================================================================
--- Modules/_testcapimodule.c (revision 51875)
+++ Modules/_testcapimodule.c (working copy)
@@ -665,6 +665,9 @@
PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
Py_END_ALLOW_THREADS
+ /* Release lock we acquired above. This is required on HP-UX. */
+ PyThread_release_lock(thread_done);
+
PyThread_free_lock(thread_done);
Py_RETURN_NONE;
}
Without that patch, there would be this error:
sem_destroy: Device busy
sem_init: Device busy
Fatal Python error: UNREF invalid object
ABORT instruction (core dumped)
Anyone have any ideas?
n
More information about the Python-Dev
mailing list