How do I force a single instance of a python app?

Richard van de Stadt stadt at cs.utwente.nl
Thu Oct 26 03:08:53 CEST 2000


Joshua Muskovitz wrote:
> 
> I need to prevent multiple copies of a python app from running
> simultaneously on a single machine.  In Windows and C++, this is done with
> sending custom window messages to all top level windows, or using some other
> kind of scheme.
> 
> I'm looking for a platform neutral way to do this for my python apps -- the
> second instance should somehow detect the first instance and should quietly
> kill itself.

This looks analogous to what is usually done when including header
files in C programs: A header file is included, and at the top of the
header file, there is some #ifdef to check if the file was included before.
Why not test this in the including file, so that the file to be included
may not need to be opened in the first place?

The analogy to your problem is that you should not let the application
test whether another instance is running, but test that before starting it.
If you use some wrapper-prog that does the test (e.g. with ps on Unix),
then it can decide whether an instance of the real application should be
started.

Richard.



More information about the Python-list mailing list