Ensure only single application instance.

Cameron Laird claird at lairds.us
Fri Aug 29 18:56:48 EDT 2008


In article <dPZtk.60600$5p1.41655 at en-nntp-06.dc1.easynews.com>,
Uberman  <bhood37 at hotmail.com> wrote:
>On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james at live.co.uk> wrote:
>> Good afternoon all.
>>
>> I have an application/script which is launched by crontab on a regular
>> basis. I need an effective and accurate way to ensure that only one instance
>> of the script is running at any one time.
>
>You could create a named pipe in /tmp with a unique (static) name and
>permissions that disallow any kind of read/write access.  Then simply have
>your script check for its existence when it starts.  If it exists, then
>another instance of your script is running, and just terminate.  Make sure
>your original instance removes the pipe when it exits.

I'll write an article on this subject this fall.  The
essentials are:
A.  There's no canonical answer; every apparent solution
    has problems;
B.  The suggestions offered you are certainly among the
    popular ones;
C.  My personal favorite is to open a (network) socket
    server.  For reasons I'll eventually explain, this
    has particularly apt semantics under Unix.



More information about the Python-list mailing list