Improves fcntl.flock usage
Project description
Improves fcntl.flock usage.
flock is a Unix command for file locking, the mecanism that controls access restrictions of files.
Usage
Exclusive blocking lock:
from flockcontext import FlockOpen with FlockOpen('/tmp/my.lock', 'w') as lock: lock.fd.write('Locked\n')
Exclusive non-blocking lock:
from flockcontext import FlockOpen try: with FlockOpen('/tmp/my.lock', 'w', blocking=False) as lock: lock.fd.write('Locked\n') except IOError as e: print('Can not acquire lock')
Shared blocking lock:
from flockcontext import Flock with FlockOpen('/tmp/my.lock', 'w', exclusive=False) as lock: lock.fd.write('Locked\n')
Acquire and release within context:
from flockcontext import FlockOpen with FlockOpen('/tmp/my.lock', 'w') as lock: print('Lock acquired') lock.fd.write('Locked\n') lock.release() print('Lock released') lock.acquire() print('Lock acquired') lock.fd.write('Locked\n')
Locking alredy opened file:
from flockcontext import Flock with open('/tmp/my.lock', 'w') as fd: with Flock(fd): fd.write('Locked\n')
License
Free software: BSD license
History
0.3.1 (2015-08-24)
Add syntax highlighting for code exemples
Add Flock manager exemple in README
0.3.0 (2015-08-21)
Add FlockOpen context manager.
0.2.0 (2015-08-20)
Add Flock relase and acquire capability withing context.
0.1.0 (2015-08-19)
Add Flock context manager.
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
flockcontext-0.3.1.tar.gz
(13.5 kB
view hashes)
Built Distribution
Close
Hashes for flockcontext-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec2c89c259bb0cb809989226d50d14adc1ed38947873a54f3633a66e605baf03 |
|
MD5 | d2892301a5ce94bbe6ceeee06541f3ea |
|
BLAKE2b-256 | 0bdad331f52d3a6bcd5a1aff0e365433d3e16a2f2dcb0daa05ee1b03ee8eed35 |