GIL in the new glossary

Skip Montanaro skip at pobox.com
Fri Oct 3 15:04:00 EDT 2003


(Rearranging your note a bit...)

    Dave> I took a quick look at the "Extending and Embedding the Python
    Dave> Interpreter" document, and did not see anything about this.

I don't think there is a "threading best practices for extension module
authors" section.

    Dave> For example, are any of the following good rules to follow?

    Dave> - Always release the GIL before I/O operations.

    Dave> - Always release the GIL at the beginning of and re-acquire it at
    Dave>   the end of any sufficiently long lasting function.

I think that's roughly correct.

    Dave> And, conversely, is there a list of situations when it would be
    Dave> dangerous or counter-productive to release the GIL in an
    Dave> extension?

That I have no idea about.  As is usually the case, the Python source itself
can be a good reference.  I executed 

    egrep -l 'Py_(BEGIN|END)_ALLOW_THREADS' *.c

in the Modules directory and identified 22 files.  Many of the modules this
revealed are very heavily used (_?bsddb, cPickle, posix, socket, time) and
thus most heavily studied.  My guess is they probable represent a sort of
"best practices" set of examples.

Skip






More information about the Python-list mailing list