Making sure script only runs once instance at a time.

Hari Sekhon hpsekhon at googlemail.com
Fri Sep 29 09:08:41 EDT 2006


Seeing as there doesn't seem to be a good answer to this (or at least 
not one that we have so far some up with) I have decided to fall back to 
my old friend the unix shell. It's as portable as python, but is very 
flexible and fast at doing real things and will tell me if another 
process by this name is running. If so, print msg and exit. simple.

-h

Hari Sekhon



MaR wrote:
> A very brutal but simple and effective method is to bind() to a socket
> on localhost eg (127.0.0.1, 4711), listen() but never accept().
> Any other process trying to to bind() on the same port will fail..
> When the process dies, the port is released automatically, pending som
> timedelay..
>
> But this assumes you have an execution environment where this is
> acceptable. A sysadmin may have objections ;o)
>
>   



More information about the Python-list mailing list