File::Flock::Retry(3) Yet another flock module


This document describes version 0.61 of File::Flock::Retry (from Perl distribution File-Flock-Retry), released on 2015-10-22.


use File::Flock::Retry;
# try to acquire exclusive lock. if fail to acquire lock within 60s, die.
my $lock = File::Flock::Retry->lock($file);
# explicitly unlock
# automatically unlock if object is DESTROY-ed.
undef $lock;


This is yet another flock module. It is a more lightweight alternative to File::Flock with some other differences:
  • OO interface only
  • Autoretry (by default for 60s) when trying to acquire lock

    I prefer this approach to blocking/waiting indefinitely or failing immediately.


$lock = File::Flock::Retry->lock($path, \%opts)

Attempt to acquire an exclusive lock on $path. $path will be created if not already exists. If $path is already locked by another process, will retry every second for a number of seconds (by default 60). Will die if failed to acquire lock after all retries.

Will automatically unlock if $lock goes out of scope. Upon unlock, will remove $path if it was created and is still empty (this behavior is the same as "File::Flock").

Available options:

  • retries => int (default: 60)

    Number of retries (equals number of seconds, since retry is done every second).

  • shared => bool (default: 0)

    By default, an exclusive lock (LOCK_EX) is attempted. However, if this option is set to true, a shared lock (LOCK_SH) is attempted.




Synonym for "unlock()".


Not yet tested on Windows. Some filesystems do not support inode?


Please visit the project's homepage at <>.


Source repository is at <>.


Please report any bugs or feature requests on the bugtracker website <>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


perlancar <[email protected]>


This software is copyright (c) 2015 by [email protected].

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.