Python Threads and C Semaphores

J

Jeremy

Hello,

I have a fat C++ extension to a Python 2.3.4 program. In all, I count
five threads. Of these, two are started in Python using
thread.start_new_thread(), and both of these wait on semaphores in the C++
extension using sem_wait(). There also are two other Python threads and one
thread running wholly in
the extension.

I notice that when one of the Python threads calls the extension and waits
on a semaphore, all but the C++ thread halt even when not waiting on any
semaphore. How do we get this working right?

Thank you,
Jeremy
 
D

Dejan Rodiger

Jeremy said the following on 16.1.2007 8:27:
Hello,

I have a fat C++ extension to a Python 2.3.4 program. In all, I count
five threads. Of these, two are started in Python using
thread.start_new_thread(), and both of these wait on semaphores in the C++
extension using sem_wait(). There also are two other Python threads and one
thread running wholly in
the extension.

I notice that when one of the Python threads calls the extension and waits
on a semaphore, all but the C++ thread halt even when not waiting on any
semaphore. How do we get this working right?

Check the Global Interpreter Lock
 
A

Andrew MacIntyre

Dejan said:
Jeremy said the following on 16.1.2007 8:27:


Check the Global Interpreter Lock

More specifically, make sure that any extension code that does not
call Python API functions releases the GIL for the duration.

Look into the Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS macros and the
PyGILState*() API functions (these API functions appeared in Python 2.3).

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top