moroz-off / python3-filelock

Flock-based file locking using Python's 3 `with` syntax

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python3-filelock

Python module for very simple flock-based file locking.

Features

  • Uses Python's with syntax.
  • Doesn't complain if the lock file already exists but is stale.
  • Cleans up the lock file after itself.
  • Supports a timeout.

Example

import fbfilelock

with fbfilelock.FileLock("/tmp/foolock.txt", 'r', encoding='UTF-8') as f:
   # Do something.
   pass

# Raises an IOError in 3 seconds if unable to acquire the lock.
with fbfilelock.FileLock("/tmp/foolock.txt", 'r', encoding='UTF-8', timeout=3, delay=0.5) as f:
   # Do something.
   pass

BUGS

Unknown.

Contributing

Contributions welcome!

About

Flock-based file locking using Python's 3 `with` syntax

License:GNU General Public License v3.0


Languages

Language:Python 100.0%