releasing interpreter lock in custom code?

Andrew MacIntyre andymac at bullseye.apana.org.au
Thu May 11 07:04:01 EDT 2006


Bram Stolk wrote:

> I've implemented, in C, a function that does a lot of I/O, and thus
> can block for a long time.
> 
> If I execute this function in my Python script, it does not 
> relinquish the global interpreter lock, like Python's native
> blocking functions do, like I/O funcs, and time.sleep() func.
> 
> How can I have my func release the lock?

Search the Python documentation (Python/C API section) for information
about the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros.

Perusing Python's source would also be educational (eg 
Modules/posixmodule.c).

-- 
-------------------------------------------------------------------------
Andrew I MacIntyre                     "These thoughts are mine alone..."
E-mail: andymac at bullseye.apana.org.au  (pref) | Snail: PO Box 370
        andymac at pcug.org.au             (alt) |        Belconnen ACT 2616
Web:    http://www.andymac.org/               |        Australia



More information about the Python-list mailing list