in reply to Problem opening file

One additional complication you might want is to make sure the script isn't in a death spiral.

my $lockfile = $destDir."loadqueue.lck"; my $failcount = 0; while ($failcount < 10000) { while (!open my $fhLock, ">", $lockfile) { print "Failed to open $lockfile: $!"; $failcount++; sleep(3); ### Changed from 3000 to 3 (parameter is seconds, +not milliseconds!) } last; }

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 SimonPratt (Friar) on Jul 08, 2015 at 16:33 UTC

    Yeah, thats one of the reasons I like die'ing. Its easy to trap and log everything without having to fill up my code with fail loops

    Ideally I would like to know why this is happening, because if the thread is stuffed at this point, it is better to continue to let it die and add handling in other locations to allow the service to catch it and spin up a replacement thread.

Re^2: Problem opening file
by GotToBTru (Prior) on Jul 08, 2015 at 19:18 UTC

    You've come up with a very robust way to hide the fact that the failure is occurring (but not forever). Kind of an XY answer - you solved the problem he was having, but not the question he's asking. UPDATE: altho he breached the idea of a workaround first.

    Dum Spiro Spero

      Also, I did address his question in my first answer, below the code.

      Ironically, I recalled the workaround part first, and then the question. Guess I was in LIFOmode today.