[python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen()

Amaury Forgeot d'Arc amauryfa at gmail.com
Sat Dec 17 17:36:06 CET 2011


2011/12/17 Scott Leerssen <sleerssen at gmail.com>

> Closing the PyHANDLE leaves the file object with an invalid descriptor,
> and closing the file object leaves the PyHANDLE with an invalid descriptor,
> but only sometimes


After open_osfhandle(), the handle is owned by the file object, and should
not be closed when the PyHANDLE object is deallocated.
Did you try to use the Detach() method? Something like
   fd = open_osfhandle(h.Detach(), os.O_RDONLY)
Documentation says: "You would call this function when you need the
underlying win32 handle to exist beyond the lifetime of the handle object"
which seems adequate here.

-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20111217/d0c24f5a/attachment.html>


More information about the python-win32 mailing list