[SciPy-user] Multithreading cookbook entry
Fri Feb 22 06:47:43 CST 2008
--- Robert Kern <firstname.lastname@example.org> 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
> > just call the Py_BEGIN_ALLOW_THREADS and
> > Py_BEGIN_ALLOW_THREADS macros in the C function
> > allow return to another thread while the C
> > 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.
More information about the SciPy-user