[capi-sig] Threading

Hrvoje Niksic hniksic at xemacs.org
Tue Sep 4 11:30:47 CEST 2007

"Pablo Yabo" <pablo.yabo at gmail.com> writes:

> The problem is that I having problems with threads. I saw that I
> have to PyEval_InitThreads and then PyThreadState_New and
> PyThreadState_Swap from the new thread but this way to solve the
> problem doesn't work for me because I need to let 2 or more threads
> run at the SAME time.

I don't know if this is still relevant, but it occurs to me that what
you want might be accomplished.  If your external library is
thread-safe, and if you're only using Python to manipulate data
managed by the library, you can simply Py_BEGIN_ALLOW_THREADS and
Py_END_ALLOW_THREADS when entering the library.  That way all calls
from Python into the library will run with threading enabled, while
the part spent in the interpreter (outside the library entry points)
will continue to run single thread at a time.  Python sources often
use this pattern when dealing with IO-bound (e.g. the file and socket
API) or CPU-bound code.

Is such a solution acceptable for you?

More information about the capi-sig mailing list