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

Martijn van der Kooij fakeadress at microsoft.com
Wed Oct 25 02:26:05 EDT 2000


> The file hack, which writes a timestamp to the file is a very interesting
> idea.  This could possibly be simplified to simply deleting and creating
the
> file and using the OS to find the file's timestamp, but this will probably
> annoy NT which doesn't like lots of temp files, and tends to fragment
> because of it.
>
> A file which contained a timestamp and a pid will probably do the trick.
I
> can live with the dead zone (the period of time between file updates) --
the
> process doesn't have to restart immediately.  Also, I was reading in the
FAQ
> today that there is a way to trap when a python app is ending -- I can
> delete the file at that point to reduce the dead zone delay when the app
> behaves well.
>

If you keep a file opened and only close it when your app is ready the file
can not be opened a second time, this way you are sure there is an other app
running if you can not create the file, otherwise as soon as you create a
lock file (and keep it open) you are sure this is the only instance.
(This works at least at Windows)

Martijn van der Kooij





More information about the Python-list mailing list