Making sure script only runs once instance at a time.

Tim Williams tim at tdw.net
Fri Sep 29 12:39:45 EDT 2006


On 29/09/06, Sybren Stuvel <sybrenUSE at yourthirdtower.com.imagination> wrote:
> Checking for a lock, and later acquiring the lock, seems non-atomic to
> me. It's easier to simply create a lock directory. If it fails, the
> dir already exists and someone else holds the lock. If it succeeds,
> the lock is immediately yours, since you just created the directory.
> This is atomic on most OSses AFAIK.

My reply was in response to a post that mentioned a known problem with
this,  what happens when the previously running program doesn't exit
gracefully, and leaves the directory in place ??

If the directory creation fails (because it already exists), it
doesn't mean there is another instance of the program running, it
means that the directory hasn't yet been deleted by its creator.

   :)



More information about the Python-list mailing list