On Dec 19, 2011, at 7:38 PM, Amaury Forgeot d'Arc wrote: > 2011/12/19 Scott Leerssen <sleers...@gmail.com> > >>> I just tried that, and after closing the file object and attempting to > >>> call win32api.ClosHandle() on the value returned by detach, I get an > >>> exception of "error: (6, 'CloseHandle', 'The handle is invalid.')" > >>> Here's what the code looks like: > >>> > >>> h = win32file.CreateFile( > >>> fname, > >>> win32file.GENERIC_READ, > >>> win32file.FILE_SHARE_READ, > >>> None, > >>> win32file.OPEN_EXISTING, > >>> win32file.FILE_FLAG_BACKUP_SEMANTICS, > >>> None > >>> ) > >>> hd = h.Detach() > >>> fd = msvcrt.open_osfhandle(hd, os.O_RDONLY) > >>> f = os.fdopen(fd, 'rb') > >>> f.read() > >>> f.close() > >>> h.Close() > >>> win32file.CloseHandle(hd) > > - h was Detach()ed, so h.Close() is a no-op. > - you should not win32file.CloseHandle(hd), the handle now owned by the file > object: > f.close() called the C function fclose(), which called close(fd) which called > CloseHandle. > > f.close() is enough here!
Thanks, that's very helpful.
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32