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)
In reply to Re: Problem opening file
by marinersk
in thread Problem opening file
by SimonPratt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |