avoid script running twice
Evan Klitzke
evan at yelp.com
Mon Jun 18 13:12:51 EDT 2007
More information about the Python-list mailing list
Mon Jun 18 13:12:51 EDT 2007
- Previous message (by thread): avoid script running twice
- Next message (by thread): avoid script running twice
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 6/18/07, Robin Becker <robin at reportlab.com> wrote: > 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. Another method that you can use is to open up a socket on some predetermined port (presumably above 1024), and then have your program try to connect to that port and "talk" to the other program to determine whether or not to run (or whether to do some of the remaining work, etc.). -- Evan Klitzke <evan at yelp.com>
- Previous message (by thread): avoid script running twice
- Next message (by thread): avoid script running twice
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list