Re: Allowing only one instance of a script?
On 2005-06-23, Aahz <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Grant Edwards <[EMAIL PROTECTED]> wrote: >> >>Both open() and link() are atomic operations, so there's no >>race condition. > > ...unless you're running under NFS. I think read somewhere than NFS 3 handles the open with CREAT+EXCL in an atomic manner (older versions didn't). I don't know about link. -- Grant Edwards grante Yow! Will it improve my at CASH FLOW? visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
In article <[EMAIL PROTECTED]>, Grant Edwards <[EMAIL PROTECTED]> wrote: > >Both open() and link() are atomic operations, so there's no >race condition. ...unless you're running under NFS. -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ f u cn rd ths, u cn gt a gd jb n nx prgrmmng. -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
In article <[EMAIL PROTECTED]>, Grant Edwards <[EMAIL PROTECTED]> wrote: . . . >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 >can. . . . While you write elsewhere in this thread, Grant, that pid-in-a-file is the "usual" way, I much prefer this technique of opening a simple TCP/IP server. While I recognize the disadvantage you describe, I choose to regard it as an opportunity--since I have launched the server anyway, I simply have it report to me (that is, any connecting client) all the information I might want want. -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2005-06-23, Tim Golden <[EMAIL PROTECTED]> 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: >> >> http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en > > 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 can. -- Grant Edwards grante Yow! I want DUSTIN at HOFFMAN!! ... I want visi.comLIBRACE!! YOW!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Thomas Guettler <[EMAIL PROTECTED]> wrote: > Create a file which contains the PID (process ID) of > the current process in a directory. If the file > already exists, the file is running. That's how it's usually done. > If your script dies without removing the pid-file, you need to > look during the start if the PID which is in the file is sill > alive. > There is a small race condition between os.path.exists() > and writing the file. That's why it's pointless to call os.path.exists(). > If you want to be 100% sure you need to use file locking. I've never seen it done that way. The standard method is to use open() with flags O_CREAT|O_EXCL. If the open() is sucessful, then you have the lock. If it fails, somebody else already has the lock. Another method is to create a temp file containing the PID and then call link() to rename it. Both open() and link() are atomic operations, so there's no race condition. -- Grant Edwards grante Yow! I don't know WHY I at said that... I think it visi.comcame from the FILLINGS inmy read molars... -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
Am Wed, 22 Jun 2005 23:49:21 -0700 schrieb Ali: > Hi, > > 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. Hi, Create a file which contains the PID (process ID) of the current process in a directory. If the file already exists, the file is running. If your script dies without removing the pid-file, you need to look during the start if the PID which is in the file is sill alive. There is a small race condition between os.path.exists() and writing the file. If you want to be 100% sure you need to use file locking. HTH, Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
On 2005-06-23, Tim Golden <[EMAIL PROTECTED]> 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: > > http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en If you're on Unix/Linux, the usual way to do this is with a lockfile. -- Grant Edwards grante Yow! I'd like MY data-base at JULIENNED and stir-fried! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Allowing only one instance of a script?
... lock file? -- http://mail.python.org/mailman/listinfo/python-list
RE: Allowing only one instance of a script?
[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: http://groups-beta.google.com/group/comp.lang.python/msg/2a4fadfd3d6e3d4b?hl=en TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Allowing only one instance of a script?
Hi, 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. Thanks Regards, Ali -- http://mail.python.org/mailman/listinfo/python-list