Tim Williams enlightened us with:
> def check_lock():
>     import os, sys
>     try:
>         os.remove({filename})
>     except:
>         if "Permission denied" in sys.exc_info()[1]:
>             print 'This program is already running'
>             sys.exit()
>     f_lock = open({filename},'w')

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.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to