Hi there,
on a Linux machine running Python 2.3.5. I want to create a file
'newfile' in a directory '/tmp' only if there is no file 'transfer.lock'
in '/temp'.
A cronjob creates a file 'transfer.lock' in '/temp' directory every 15
minutes while the cronjob is doing something. This job takes
Nico Grubert enlightened us with:
How can I use a timer that waits e.g. 10 seconds if 'transfer.lock'
is present and then checks again if 'transfer.lock' is still there?
Make a while loop in which you sleep. Or use the threading module if
you want to go multi-threading.
Sybren
--
The problem
Nico Grubert wrote:
Hi there,
on a Linux machine running Python 2.3.5. I want to create a file
'newfile' in a directory '/tmp' only if there is no file 'transfer.lock'
in '/temp'.
A cronjob creates a file 'transfer.lock' in '/temp' directory every 15
minutes while the cronjob is doing
Hi Sybren and Wolfram,
thank you very much for the time.sleep() tip.
My program reads like this now.
import os
import time
WINDOWS_SHARE = 'C:\\Temp'
while 'transfer.lock' in os.listdir( WINDOWS_SHARE ):
print Busy, please wait...
time.sleep(10)
f = open(WINDOWS_SHARE + '/myfile',
Nico Grubert [EMAIL PROTECTED] writes:
while 'transfer.lock' in os.listdir( WINDOWS_SHARE ):
print Busy, please wait...
time.sleep(10)
f = open(WINDOWS_SHARE + '/myfile', 'w')
But there's a race condition, and don't you have to make your own lock
before writing myfile, so that the
Nico Grubert [EMAIL PROTECTED] wrote:
on a Linux machine running Python 2.3.5. I want to create a file
'newfile' in a directory '/tmp' only if there is no file 'transfer.lock'
in '/temp'.
A cronjob creates a file 'transfer.lock' in '/temp' directory every 15
minutes while the cronjob
That all sounds very race-y to me! The cron-job and the other process
need to take the same lock, otherwise the cron-job will start 1ms
after the other process checks for transfer.lock and before it has a
chance to create newfile and there will be trouble.
Using files as locks isn't
Nico Grubert [EMAIL PROTECTED] 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