in reply to Problem opening file
No need to get complicated. If you don't want the script to die, don't use die.
my $lockfile = $destDir."loadqueue.lck"; while (!open my $fhLock, ">", $lockfile) { print "Failed to open $lockfile: $!"; sleep(3); ### Changed from 3000 to 3 (parameter is seconds, +not milliseconds!) }
As to why it's failing -- without more information, hard to tell. My guess is that in the process of opening a file -- usually an atomic operation -- the thread may have stepped on something another thread was doing (or vice versa), and failed without a highly visible cause.
Thus, my first stab at a workaround was to let it breathe 3 seconds (or whatever is appropriate for the environment) and try again.
Edit: Changed sleep(3000)to sleep(3)(stupid human tricks when switching back and forth between languages)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem opening file
by kcott (Archbishop) on Jul 08, 2015 at 17:03 UTC | |
by marinersk (Priest) on Jul 08, 2015 at 17:29 UTC | |
by ww (Archbishop) on Jul 08, 2015 at 20:25 UTC | |
by marinersk (Priest) on Jul 08, 2015 at 22:08 UTC | |
|
Re^2: Problem opening file
by SimonPratt (Friar) on Jul 09, 2015 at 09:38 UTC | |
by marinersk (Priest) on Jul 09, 2015 at 13:54 UTC | |
by SimonPratt (Friar) on Jul 10, 2015 at 10:33 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2015 at 11:12 UTC |