This package contains a single module, which implements a platform independent file locking mechanism for Python.
The lock includes a lock counter and is thread safe. This means, that when you lock the same lock object (in the same application) twice, you will get no timeout error.
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()
# You can even nest the lock or acquiring it multiple times in the same
# application.
with lock:
assert lock.is_locked()
with lock:
assert lock.is_locked()
assert lock.is_locked()
assert (not lock.is_locked())
License
This package is public domain.
Metadata
Release files for filelock 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| filelock-1.0.2.zip | 7.7 kB | Without provenance | Details |
Release files / filelock-1.0.2.zip
| Download URL | filelock-1.0.2.zip |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2f61327bcaf7733220775ec66d36b2568735df89db7d9f7d2a2c2fb6003c34f
|
|
BLAKE2b-256 checksum How to use checksums |
1b1203c739fbb2b50da7847c6604d7ec96a63bae75e640f4722831a0e5cc2262
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for filelock 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.