How to use a timer in Python?

2005-09-23 Thread Nico Grubert
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

Re: How to use a timer in Python?

2005-09-23 Thread Sybren Stuvel
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

Re: How to use a timer in Python?

2005-09-23 Thread Wolfram Kraus
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

Re: How to use a timer in Python?

2005-09-23 Thread Nico Grubert
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',

Re: How to use a timer in Python?

2005-09-23 Thread Paul Rubin
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

Re: How to use a timer in Python?

2005-09-23 Thread Nick Craig-Wood
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

Re: How to use a timer in Python?

2005-09-23 Thread Nico Grubert
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

Re: How to use a timer in Python?

2005-09-23 Thread Nick Craig-Wood
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