# Py-FileLock
This package contains a single module [filelock](filelock.py), which implements
a platform independent file locking mechanism for Python.
## Examples
```Python
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](LICENSE.md).
This package contains a single module [filelock](filelock.py), which implements
a platform independent file locking mechanism for Python.
## Examples
```Python
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](LICENSE.md).
Metadata
Release files for filelock 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| filelock-0.2.0.zip | 7.1 kB | Details |
Release files / filelock-0.2.0.zip
| Download URL | filelock-0.2.0.zip |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01df3f204f1e02a81550daf07a6b29a5c08b9a46dc61ed0e644b334ca9b448fb
|
|
BLAKE2b-256 checksum How to use checksums |
5db7979e97be7d422ce8f203e2305f8f26d2a4baed7267e16324593bd27f2701
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |