Menu

#686 GIL is held while calling CreateFileW.

v1.0 (example)
closed-fixed
nobody
5
2015-05-20
2015-02-06
No

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.

Discussion

  • Lukasz Anforowicz

    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).

     
  • Mark Hammond

    Mark Hammond - 2015-05-20

    Thanks Roger!

     
  • Mark Hammond

    Mark Hammond - 2015-05-20
    • status: open --> closed-fixed