[SciPy-user] Multithreading cookbook entry

Lou Pecora lou_boog2000@yahoo....
Fri Feb 22 06:47:43 CST 2008


--- Robert Kern <robert.kern@gmail.com> wrote:


> ctypes releases the GIL when it calls a C function.
> Some C functions
> take callbacks; ctypes lets you pass Python
> functions as these
> callbacks. There is a C stub wrapped around the
> Python function to
> handle the communication. This stub reacquires the
> GIL before calling
> the Python function.

> >  How do I tell if the C function is thread safe?

> You have to analyze the C function and the way you
> are calling it.
> It's not necessarily an easy thing. Basically, you
> have to make sure
> that concurrent calls to your functions don't touch
> the same data.

> >  My C function will make NO Python API calls. Can
> I
> >  just call the Py_BEGIN_ALLOW_THREADS and
> >  Py_BEGIN_ALLOW_THREADS macros in the C function
> to
> >  allow return to another thread while the C
> function
> >  calculates?

> With ctypes, this is not necessary.

Robert, thanks very much for clarifying that.  I get
it.  ctypes is certainly more sophisticated than I
realized!  Very nice.  I am even more in debt to those
who pushed me to use it.




-- Lou Pecora,   my views are my own.


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


More information about the SciPy-user mailing list