multiple instance on Unix

David Bolen db3l at fitlinxx.com
Thu Sep 30 19:44:16 CEST 2004


Mike Meyer <mwm at mired.org> writes:

> The (old) standard method for locking on Unix is to use a file. Open
> it in exclusive mode. Using os.open(<filename>, O_EXCL | O_RDONLY) (or
> O_WRONLY, or O_RDWR) should do the trick.

The oldest methods I tended to use still went the mkdir() route, since
that tends to be more reliable across NFS links (where the MKDIR
operation is still generally atomic, and doesn't involve NFS
machinations to support locking).  And if you're using a filesystem to
implement stuff like this you may not know if it's local or not.

-- David



More information about the Python-list mailing list