How to use a timer in Python?
nick at craig-wood.com
Fri Sep 23 13:30:02 CEST 2005
Nico Grubert <nicogrubert at gmail.com> wrote:
> There is no cronjob anymore now. I just need to check if there is a lock
> file. How would you modify my short program to avoid the situation "Ie
> someone can get in there after you read the directory but before
> you create the file."?
You can't do it with files.
You can do it with directories though...
Both processes need to be using the same lock, so something like this
(all untested ;-)
WINDOWS_SHARE = 'C:\\Temp'
lock_file = os.path.join(WINDOWS_SHARE, "transfer.lock")
gained_lock = False
while not gained_lock:
gained_lock = True
print "Busy, please wait..."
f = open(WINDOWS_SHARE + '/myfile', 'w')
You need to do the same thing to the program which currently creates
transfer.lock - so it waits if the transfer.lock is in existence too.
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list