A platform independent file lock.
Project description
This package contains a single module, which implements a platform independent file locking mechanism for Python.
Examples
import filelock
lock = filelock.FileLock("my_lock_file")
# This is the easiest way to use the file lock. Note, that the FileLock
# object blocks until the lock can be acquired.
with lock:
print("Doing awesome stuff")
# If you don't want to wait an undefined time for the file lock, you can use
# the *acquire* method to provide a *timeout* paramter:
try:
with lock.acquire(timeout=10):
print("Doing more awesome stuff!")
except filelock.Timeout as err:
print("Could not acquire the file lock. Leaving here!")
exit(1)
# When you're using Python 3.3+, *filelock.Timeout* is a subclass of
# *TimeoutError* else OSError. So you can do this too:
try:
with lock.acquire(timeout=10):
print("Doing more awesome stuff!")
except TimeoutError as err:
print("Could not acquire the file lock. Leaving here!")
exit(1)
# If you don't want to use or if you can't use the *with-statement*, the
# example above is equal to this one:
try:
lock.acquire(timeout=10)
except filelock.Timeout as err:
print("Could not acquire the file lock. Leaving here!")
exit(1)
else:
print("Doing more awesome stuff!")
finally:
lock.release()
License
This package is public domain.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
filelock-0.2.2.zip
(7.1 kB
view details)
File details
Details for the file filelock-0.2.2.zip
.
File metadata
- Download URL: filelock-0.2.2.zip
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ff0b6607c1889d139074fb09cb001f6cc6d835c5222a6a95559683521ba5d7 |
|
MD5 | c612d9fb3d32e3ff014629cd6b676e7d |
|
BLAKE2b-256 | 83419fe5ecedfff9cf849c61b2cbdfadda233ccb7d65ea27588f29c89e672d81 |