Threading a lengthy C function

Leo Breebaart leo at lspace.org
Tue Nov 25 04:51:07 EST 2003


My thanks to everyone who participated in this, ahem, thread.
Your responses have been very helpful -- this newsgroup is a
wonderful resource for the beginning Python programmer.


Duncan Booth <duncan at NOSPAMrcp.co.uk> writes:

> It may be easiest simply to wrap the library function in another C function 
> that does this, and then use SWIG to wrap the new function instead of the 
> original. e.g.
> 
> #include <python.h>
> int safe_thefunction(char *arg, int arg2)
> {
>    int res;
>    Py_BEGIN_ALLOW_THREADS
>    res = thefunction(arg, arg2);
>    Py_END_ALLOW_THREADS
>    return res;
> }

This is more or less exactly what I ended up doing, and
everything works like a charm now.

-- 
Leo Breebaart  <leo at lspace.org>




More information about the Python-list mailing list