Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Scheduling Perl Tasks

by marioroy (Prior)
on Mar 23, 2017 at 23:24 UTC ( [id://1185696]=note: print w/replies, xml ) Need Help??


in reply to Re: Scheduling Perl Tasks
in thread Scheduling Perl Tasks

That's a good point Corion regarding locking $0. I updated the code by not appending the suffix ".lock" when path is given. The lock is released automatically upon termination of the script.

use Mutex::Flock; ( my $mutex = Mutex::Flock->new( path => $0 ) )->lock_exclusive; ...

Another way, with the timewait method.

my $mutex = MCE::Mutex::Flock->new( path => $0 ); # terminate script if a previous instance is still running exit unless $mutex->timedwait(2); ...

The module is beneficial regarding supporting threads and processes. I will make time to complete it and subsequently a release for CPAN.

Regards, Mario

Edit: Added timedwait example.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found