A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/313171.html below:

How to use a timer in Python?

How to use a timer in Python?Nico Grubert nicogrubert at gmail.com
Fri Sep 23 02:21:51 EDT 2005
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 around 30 
seconds. During these 30 seconds the 'transfer.lock' file is present in 
the '/temp' directory and I must not create 'newfile'. After the cronjob 
has been finished, the 'transfer.lock' file is deleted from '/temp' and 
I can create 'newfile'.
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?

I want to do something like this:

import os
if 'transfer.lock' in os.listdir('/temp'):
   # ...wait 10 seconds and then check again if
   # 'transfer.lock' is in os.listdir('/temp')
else:
   # create 'newfile'


Nico

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4