Allowing only one instance of a script?

Grant Edwards grante at
Thu Jun 23 17:01:11 CEST 2005

On 2005-06-23, Grant Edwards <grante at> wrote:
> On 2005-06-23, Tim Golden <tim.golden at> wrote:
>> [Ali]
>>| I have a script which I double-click to run. If i double-click it
>>| again, it will launch another instance of the script.
>>| Is there a way to allow only one instance of a script, so that if
>>| another instance of the script is launched, it will just 
>>| return with an
>>| error.
>> If you're on Windows, have a look at this recent thread:
> If you're on Unix/Linux, the usual way to do this is with a
> lockfile.

You can also use a network port instead of a file.  Binding a
socket to a port is an exclusive and atomic operation.  An
advantage to the network port scheme is that the "lock"
automatically goes away if the program dies.  A disadvantiage is
that it can't contain information (date/time/PID) like a file

Grant Edwards                   grante             Yow!  I want DUSTIN
                                  at               HOFFMAN!! ... I want
                                 LIBRACE!! YOW!!

More information about the Python-list mailing list