Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Lock File

by McDarren (Abbot)
on Nov 03, 2010 at 04:54 UTC ( #869136=note: print w/ replies, xml ) Need Help??


in reply to Lock File

Here is a technique that I picked up here at the monastery a few years back, and have been using ever since:

use Fcntl 'LOCK_EX', 'LOCK_NB'; unless (flock DATA, LOCK_EX | LOCK_NB) { $logger->fatal("Found duplicate script run. Stopping"); exit; } __DATA__ This exists to allow the locking code at the beginning of the file to +work. DO NOT REMOVE THESE LINES!
If I can find the original node, I'll update with a link to it.
Update: Found it. this node by adamk.

Cheers,
Darren


Comment on Re: Lock File
Download Code
Replies are listed 'Best First'.
Re^2: Lock File
by eyepopslikeamosquito (Chancellor) on Nov 03, 2010 at 08:44 UTC
Re^2: Lock File
by JavaFan (Canon) on Nov 03, 2010 at 13:28 UTC
    You actually don't need the latter two lines. Just having either __DATA__ or __END__ will do.

      The text after the __DATA__ is required. Without it, the program will stop working as soon as a coworker tries to improve the code. :P

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://869136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (17)
As of 2015-07-28 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls