GIL is held while calling CreateFileW.
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
I have a heap dump that upon inspection shows GIL being held during a call to CreateFileW. This seems like a bug in win32file module.
The definition of CreateFile (on line 233 of win32file.i) uses SWIG wrapper, which I assume is responsible for generating a pair of Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS.
The definition of CreateFileW (on line 4549 of win32file.i) is hand-written / doesn't go through a SWIG wrapper and doesn't seem to release GIL (i.e. unlike other nearby functions [say py_WriteEncryptedFileRaw] it doesn't explicitly use Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS.
CreateFileW usually returns quickly, but in case of network-based file systems it can block for seconds (so holding GIL while calling CreateFileW is rather undesirable).
Fixed in this commit:
http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=b57d0d7444fb
Thanks Roger!