tags:

views:

109

answers:

4

I am looking to make a python script be unique in the sense that it can only run once at a time. For example if I run the script and open another session of the same script a second time and the first session is still running, then the second session will just exit and do nothing. Anyone knows how I could implement this?

A: 

Already answered here.

RSabet
This should be a comment RSabet, not an answer. I have voted to close the OP as exact duplicate btw
OscarRyz
A: 

One poor man's solution is to use a file based lock. If you open a file using os.open(), there is a flag that allows an exclusive lock on the file. See this for reference.

CruiZen
A: 

Maybe you can read/write some flag to a common archive at the start (to check for the flag value and to set the flag on) and end (to set the flag off) of the run. If the flag indicates another program already is working, the second program stops

joaquin
+1  A: 

Thanks all for pointing me in the right direction. This is the solution I picked: http://code.activestate.com/recipes/474070/

Richard