Hi - > -----Original Message----- > From: Deb [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 20, 2003 12:42 PM > To: [EMAIL PROTECTED] > Subject: shlock and retrying > > > Hi, > > I need to modify some code that check for the existance of a lockfile: > > unless (&shlock("$somedir/.cache.LOCK")) { > print "$main'program_name: cache already running\n" if $verbose; > exit; > } > > I don't want to "exit" if I find the lock there. What I need to do is > back off for a short period of time (a few seconds?) then try again, until > the lockfile is gone. > > I'm not sure what might be the best way to approach this. I'm not comfy > with an indefinite loop, where if there is some problem removing > the lockfile, > my program would wait forever. I'd rather try for a few minutes, > then exit > with some error. > > Any pearls of wisdom out there? I could use a boost... > > Thanks, > > deb >
Unless I'm missing the mark, 'sleep' and some simple math should work, as in: my $RETRY_SECONDS = 5; # try lock every 5 seconds my $TRY_FOR = 300; # fail after 5 minutes my $try_time = 0; while (1) { last if &shlock("$somedir/.cache.LOCK"); sleep $RETRY_SECONDS; $try_time += $RETRY_SECONDS; if ($try_time > $TRY_FOR) { print "$main'program_name: cache already running\n" if $verbose; exit; } } ...OK from here... Aloha => Beau; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]