[Python-ideas] Add create mode to open()

Nick Coghlan ncoghlan at gmail.com
Wed Aug 17 06:11:32 CEST 2011

On Wed, Aug 17, 2011 at 1:43 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> I'd also point out that for those that don't want race conditions,
> Python is discouraging. The correct incantation involves two
> undocumented constants, plus a unique and rarely used way of opening
> files that involves unix file descriptors.

FWIW, when you control the filename, you can include an additional
subdirectory precisely for the exception when a second process
attempts to create the same subdirectory. You can even play games
along those lines for file access control on arbitrary filenames via a
shadow hierarchy of directories.

For example, Skip's lockfile package
(http://packages.python.org/lockfile/lockfile.html) uses directories
to provide cooperative file locks on Windows.

That only helps the cooperative locking case, though - it does nothing
against hostile file substitutions.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list