This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sbt
Recipients sbt
Date 2012-07-03.19:14:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1341342894.98.0.559958462018.issue15244@psf.upfronthosting.co.za>
In-reply-to
Content
On Unix, files (unless specifically locked) can be renamed and deleted while file descriptors for the file remain open.  The file descriptors remain valid even after deletion of the file.

On Windows this is not possible for files opened using io.open() or os.open().  However, by using the FILE_SHARE_DELETE flag in CreateFile() one can get Unix-like behaviour.

Unfortunately, FILE_SHARE_DELETE is only available through the Win32 API, not through the CRT.  Also, Issue #14243 concerns the fact that on Windows temporary files cannot be reopened unless one uses the FILE_SHARE_DELETE flag.  One can only reopen a file by using a share mode that is at least as permissive as the share mode for all the currently open handles.

The attached patch adds a module "share" (bad name?) with functions share.open() and share.os_open() which act as substitutes for io.open() and os.open().  These by default use FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE as the share mode.  (io.open() and os.open() use FILE_SHARE_READ | FILE_SHARE_WRITE instead.)

To run the full regression test suite with builtins.open(), io.open() and os.open() monkey patched to use these replacements you can do

    python -m test.test_share --regrtest

Nothing seems to break.
History
Date User Action Args
2012-07-03 19:14:55sbtsetrecipients: + sbt
2012-07-03 19:14:54sbtsetmessageid: <1341342894.98.0.559958462018.issue15244@psf.upfronthosting.co.za>
2012-07-03 19:14:54sbtlinkissue15244 messages
2012-07-03 19:14:54sbtcreate