Threading a lengthy C function
theller at python.net
Thu Nov 20 18:24:53 CET 2003
sdd <daniels at dsl-only.net> writes:
> Leo Breebaart wrote:
>> If, however, I use the kind of run() method that I *really* need:
>> def run(self):
>> retvalue = mypackage.sleep(50)
>> where mypackage.sleep() is in fact a SWIG-generated wrapper
>> around the C library sleep() function the entire application
>> will *still* lock up completely until this task is done.
> As you suspect, this is the GIL at work.
I always wondered why (apparently) SWIG does not release the lock before
calling into C code and acquire it back afterwards.
If the original posters intent is simply to call functions in a dll, he
should probably try out ctypes - ctypes handles the GIL automatically
(release before calling the function, acquire it back after return of
the function, and even grabbing the GIL if a callback into Python is
done). And it avoids SWIG completely.
More information about the Python-list