Dev-Util
view release on metacpan or search on metacpan
docs/Sem.md view on Meta::CPAN
Dev::Util::Sem - Module to do Semaphore locking
# VERSION
Version v2.19.35
# SYNOPSIS
To ensure that only one instance of a program runs at a time,
create a semaphore lock file. A second instance will wait until
the first lock is unlocked before it can proceed or it times out.
use Dev::Util::Sem;
my $sem = Sem->new('mylock.sem');
...
$sem->unlock;
# EXPORT
new
examples/semaphore_test.pl view on Meta::CPAN
say "go to sleep - 5 sec";
sleep 5;
say "wake up";
say "unlocking";
$sem->unlock;
say "unlocked";
say "end";
lib/Dev/Util/Sem.pm view on Meta::CPAN
Dev::Util::Sem - Module to do Semaphore locking
=head1 VERSION
Version v2.19.35
=head1 SYNOPSIS
To ensure that only one instance of a program runs at a time,
create a semaphore lock file. A second instance will wait until
the first lock is unlocked before it can proceed or it times out.
use Dev::Util::Sem;
my $sem = Sem->new('mylock.sem');
...
$sem->unlock;
=head1 EXPORT
new
is( file_size_equals( $expected_dir . $lock_filename, 35 ),
1, "Lockfile should be 35 characters" );
like(
dies {
my $semB = Dev::Util::Sem->new( $lock_filename, 1 );
$semB->{ fh }->autoflush();
$semB->{ fh }->print("to come to the aid of their country!");
},
qr{Timeout aquiring the lock},
"Fails when lock file is locked"
);
$semA->unlock;
is( file_exists( $expected_dir . $lock_filename ),
0, "Lockfile in default dir should be gone now via unlock" );
done_testing;
( run in 1.338 second using v1.01-cache-2.11-cpan-39bf76dae61 )