Re: avoid script running twice

2007-06-19 Thread Robin Becker
Nick Craig-Wood wrote: > Tim Williams <[EMAIL PROTECTED]> wrote: >> On 18/06/07, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >> On Windows the open-a-file-for-writing method works well, but as *nix >> doesn't work the same way then maybe the socket solution is the best >> cross-platform option.

Re: avoid script running twice

2007-06-18 Thread Gabriel Genellina
En Mon, 18 Jun 2007 16:30:05 -0300, Nick Craig-Wood <[EMAIL PROTECTED]> escribió: > Tim Williams <[EMAIL PROTECTED]> wrote: >> You can also do this by holding a file open in write mode until the >> script has finished. >> >>try: >> open('lock.txt','w') >> my_scr

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
Tim Williams <[EMAIL PROTECTED]> wrote: > On 18/06/07, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > On Windows the open-a-file-for-writing method works well, but as *nix > doesn't work the same way then maybe the socket solution is the best > cross-platform option. Actually you could combine y

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
Jeff McNeil <[EMAIL PROTECTED]> wrote: > I've got a rather large log processing job here that has the same > requirement. I process and sort Apache logs from an 8-way cluster. I > sort and calculate statistics in 15-minute batch jobs. Only one copy > should run at once. > > I open a file and

Re: avoid script running twice

2007-06-18 Thread Jeff McNeil
Note that in real life, the script exits cleanly if another copy is running... On 6/18/07, Jeff McNeil <[EMAIL PROTECTED]> wrote: > I've got a rather large log processing job here that has the same > requirement. I process and sort Apache logs from an 8-way cluster. I > sort and calculate statist

Re: avoid script running twice

2007-06-18 Thread Jeff McNeil
I've got a rather large log processing job here that has the same requirement. I process and sort Apache logs from an 8-way cluster. I sort and calculate statistics in 15-minute batch jobs. Only one copy should run at once. I open a file and lock it via something like this: import fcntl fhandle

Re: avoid script running twice

2007-06-18 Thread David Wahler
On 6/18/07, Robin Becker <[EMAIL PROTECTED]> wrote: > Evan Klitzke wrote: > > Another method that you can use is to open up a socket on some > > predetermined port (presumably above 1024), and then have your program > > try to connect to that port and "talk" to the other program to > > determine wh

Re: avoid script running twice

2007-06-18 Thread Tim Williams
On 18/06/07, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Tim Williams <[EMAIL PROTECTED]> wrote: > > You can also do this by holding a file open in write mode until the > > script has finished. > > > >try: > > open('lock.txt','w') > > my_script() > > except:

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
Robin Becker <[EMAIL PROTECTED]> wrote: > I looked at the temporary files idea, but I'm not certain about the exact > details. Normally your create a file and then remove it whilst keeping the > file > handle; that allows your program to write to it whilst guaranteeing that it > will > van

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
Tim Williams <[EMAIL PROTECTED]> wrote: > You can also do this by holding a file open in write mode until the > script has finished. > >try: > open('lock.txt','w') > my_script() > except: >#print script is already running That only works under w

Re: avoid script running twice

2007-06-18 Thread Jay Loden
Robin Becker wrote: > I wish to prevent a python script from running twice; it's an hourly job, but > can take too long. > > My simplistic script looks like > > > ... > def main(): > fn = 'MARKER' > if os.path.isfile(fn): > log('%s: hourly job running already' % formatTi

Re: avoid script running twice

2007-06-18 Thread Tim Williams
On 18/06/07, Robin Becker <[EMAIL PROTECTED]> wrote: > Wildemar Wildenburger wrote: > > Robin Becker wrote: > . > > > > Well I can think of a dumb way: create a temporary file during the > > transaction and have your script check for that before running its main > > body. > > > > > > I thin

Re: avoid script running twice

2007-06-18 Thread Evan Klitzke
On 6/18/07, Robin Becker <[EMAIL PROTECTED]> wrote: > Evan Klitzke wrote: > > > > > > Another method that you can use is to open up a socket on some > > predetermined port (presumably above 1024), and then have your program > > try to connect to that port and "talk" to the other program to

Re: avoid script running twice

2007-06-18 Thread Robin Becker
Wildemar Wildenburger wrote: > Robin Becker wrote: > > Well I can think of a dumb way: create a temporary file during the > transaction and have your script check for that before running its main > body. > > > I think thats the most hassle free way of doing it. > /W I looked at the te

Re: avoid script running twice

2007-06-18 Thread Robin Becker
Evan Klitzke wrote: > > Another method that you can use is to open up a socket on some > predetermined port (presumably above 1024), and then have your program > try to connect to that port and "talk" to the other program to > determine whether or not to run (or whether to do some of the

Re: avoid script running twice

2007-06-18 Thread Evan Klitzke
On 6/18/07, Tim Williams <[EMAIL PROTECTED]> wrote: > On 18/06/07, Evan Klitzke <[EMAIL PROTECTED]> wrote: > > On 6/18/07, Robin Becker <[EMAIL PROTECTED]> wrote: > > > I wish to prevent a python script from running twice; it's an hourly job, > > > but > > > can take too long. > > > > > > My simpl

Re: avoid script running twice

2007-06-18 Thread Tim Williams
On 18/06/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > Robin Becker wrote: > > I wish to prevent a python script from running twice; it's an hourly job, > > but > > can take too long. > > > > [snip] > > but it occurs to me that I might be killed with prejudice during the long > > running

Re: avoid script running twice

2007-06-18 Thread Tim Williams
On 18/06/07, Evan Klitzke <[EMAIL PROTECTED]> wrote: > On 6/18/07, Robin Becker <[EMAIL PROTECTED]> wrote: > > I wish to prevent a python script from running twice; it's an hourly job, > > but > > can take too long. > > > > My simplistic script looks like > > > > > > ... > > def main(): > >

Re: avoid script running twice

2007-06-18 Thread Wildemar Wildenburger
Robin Becker wrote: > I wish to prevent a python script from running twice; it's an hourly job, but > can take too long. > > [snip] > but it occurs to me that I might be killed with prejudice during the long > running work(). Is there a smart way to avoid running simultaneously. > Well I can

Re: avoid script running twice

2007-06-18 Thread Evan Klitzke
On 6/18/07, Robin Becker <[EMAIL PROTECTED]> wrote: > I wish to prevent a python script from running twice; it's an hourly job, but > can take too long. > > My simplistic script looks like > > > ... > def main(): > fn = 'MARKER' > if os.path.isfile(fn): > log('%s: hourly job