A unique instance of Python GUI program

Grant Edwards invalid at invalid
Thu Sep 18 10:59:24 EDT 2008


On 2008-09-16, akineko <akineko at gmail.com> wrote:

> This may not be a Python specific challenge. I have a GUI
> program written in Python + Tkinter. It works very well.
>
> Now, I would like to start it from a shell script. As my GUI
> program includes a server, it should not have more than one
> instance. Is there any easy way to check if another instance
> of the program is already running.
>
> I vaguely remember that Windows programming provides a way to
> check.

On unix the solution is usually a lockfile placed in a
predefined location.  Other people use a socket, but that's a
bit more susceptible to namespace collisions with unrelated
programs.

> A platform independent approach would be nice but a solution
> for X is sufficient for my application.

I don't see what X has to do with it.

> Any comments will be greatly appreciated.

This question is asked and answered about once a week, and I'm
always surprised at how frequently it comes up.  I've been
doing sw development for decades and apart from Unix system
daemons, I don't remember ever needing to prevent multiple
instances of an application from running.  Can somebody lend me
a clue as to why this question comes up so often? There can't
be that many people writing Unix daemons in Python (and if they
were, they'd probably already know about lockfiles).

Just curious...

-- 
Grant Edwards                   grante             Yow! Is something VIOLENT
                                  at               going to happen to a
                               visi.com            GARBAGE CAN?



More information about the Python-list mailing list