Making sure script only runs once instance at a time.

Fredrik Lundh fredrik at pythonware.com
Fri Sep 29 10:45:06 EDT 2006


Hari Sekhon wrote:

> I'm not sure if that is a very old way of doing it, which is why I was 
> reluctant to do it. My way actually uses the process list of the os 
> (linux) and counts the number of instances. If it is more than 0 then 
> another process is running and the script exits gracefully.

the code that reliably identifies instances of a given program would be 
interesting to see.

> Also, apart from the fact the using lockfiles feels a bit 1970s, I have
 > found that in real usage of other programs within the company that use
 > lockfiles, it sometimes causes a bit of troubleshooting time when
 > it stops working due to a stale lockfile.

to minimize that risk, store the pid in the lockfile (and preferrably 
also the host name), and make sure that the program checks that the pid 
is still active before it "stops working".

</F>




More information about the Python-list mailing list