avoid script running twice

R

Robin Becker

I wish to prevent a python script from running twice; it's an hourly job, but
can take too long.

My simplistic script looks like


........
def main():
fn = 'MARKER'
if os.path.isfile(fn):
log('%s: hourly job running already' % formatTime())
else:
f = open(fn,'w')
f.write(str(os.getpid()))
f.close()
try:
work()
finally:
os.remove(fn)

if __name__=='__main__':
main()

but it occurs to me that I might be killed with prejudice during the long
running work(). Is there a smart way to avoid running simultaneously.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top