473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Python Threads and C Semaphores

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
2 1948
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: andrewpalumbo | last post by:
I'm trying to write some code which will split up a vector into two halves and run a method on the objects in the vector using two seperate threads. I was hoping to see a near linear speedup on an...
5
by: Bart Nessux | last post by:
Could someone explain the concept of threads and how I might use them in Python? I was a math major, not a CS major (theory instead of practice). Most of my programming knowledge has grown out of...
1
by: Mark E. Hamilton | last post by:
Sorry, I probably should have re-stated the problem: We're using Python 2.3.5 on AIX 5.2, and get the follow error messages from some of our code. I haven't yet tracked down exactly where it's...
5
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or...
4
by: daniel | last post by:
Hello, Can anyone explain the main points in working with threads in Python. Why use threading and not Thread.I have read an article that i have to subclass the Thread class and override some...
12
by: emma_middlebrook | last post by:
Hi Say you had N threads doing some jobs (not from a shared queue or anything like that, they each know how to do their own set of jobs in a self-contained way). How can you coordinate them so...
5
by: Svein Seldal | last post by:
Hi, I have a C-application that calls a Python function main(). This function will loop forever and not return until the entire application is about to terminate. In a parallel C-thread, some...
9
by: Randy.Galbraith | last post by:
I'm investigating the possible use of Mecurial SCM as a replacement for CVS. Mecurial is written in Python. I have a background in GNU/ Linux, Solaris, sparc and Perl. However AIX, powerpc and...
9
by: YouCanCallMeAl | last post by:
It seems that the multiprocessing module in 2.6 is broken for *BSD; I've seen issue 3770 regarding this. I'm curious if there are more details on this issue since the posts in 3770 were a bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.