By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Python Threads and C Semaphores

P: n/a
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
Jan 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
Jan 16 '07 #2

P: n/a
Dejan Rodiger wrote:
Jeremy said the following on 16.1.2007 8:27:
>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
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).

--
-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Jan 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.