471,348 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

avoid script running twice

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.
--
Robin Becker

Jun 18 '07 #1
0 1092

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Danny Wang | last post: by
5 posts views Thread by Peter Rilling | last post: by
8 posts views Thread by TS | last post: by
17 posts views Thread by PJ | last post: by
15 posts views Thread by Lawrence Krubner | last post: by
1 post views Thread by naveenkongati | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.