Skip to main content
https://img.shields.io/travis/AntoineCezar/flockcontext.svg https://img.shields.io/badge/docs-latest-brightgreen.svg https://img.shields.io/coveralls/AntoineCezar/flockcontext.svg https://img.shields.io/pypi/v/flockcontext.svg

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 blocking lock with 1 second timeout:

from flockcontext import FlockOpen

with FlockOpen('/tmp/my.lock', 'w', timeout=1) 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 already 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

Metadata

Release files for flockcontext 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flockcontext 1.0.0
File Size Uploaded
flockcontext-1.0.0.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flockcontext 1.0.0
File Interpreter ABI Platform
flockcontext-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / flockcontext-1.0.0.tar.gz

Download URL flockcontext-1.0.0.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
16c69ffdf483b5bef6cabf70b7fc830d5cf6e8e6708e61bd26a32738c683d523
BLAKE2b-256 checksum
How to use checksums
4dd41274ea691160ab4066e6e206f3d7ae245a81691b7f602f72ffb0d1f24d1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / flockcontext-1.0.0-py3-none-any.whl

Download URL flockcontext-1.0.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e38a0748fb4294591c3e20ae16ba9b4ec30f6e2f0494faf15aed28da4779ddf
BLAKE2b-256 checksum
How to use checksums
34810b88b8aafed29c50236d416af34bba6fd1760c3be801facc387b4b3cb2b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.4.0

2 release files

0.3.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page