Skip to main content

flockfile

Just a simple python lock file class using file locks.

Installation

pip install flockfile

Usage

from flockfile import FlockFile, FileNotLocked

# init the class using a file name
# optionally, the directory can be set to something other than /tmp
lock = FlockFile("myscriptname", lock_dir="/tmp")


# lock the file
lock.lock()
# if this is unsuccessful, exception FileNotLocked will be raised.

# the following class method can be used to check lock status
assert lock.check_lock()

# unlock and delete file
lock.unlock()

FlockFile can also be used as a context manager. The lock is acquired on entry (raising FileNotLocked if it cannot be obtained) and released on exit:

from flockfile import FlockFile

with FlockFile("myscriptname", lock_dir="/tmp"):
    # the lock is held here
    ...
# the lock is released and the file deleted here

Questions or Issues?

Please report as a Gitlab issue: https://gitlab.com/rveach/flockfile/issues

A note on the use of AI

This library was initally created by hand and uploaded to PyPI in 2019. A lot has changed, so I've used AI to add a context manager and modernize the toolset. All commits using AI have been tagged as such.

Metadata

Release files for flockfile 0.2.3

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

Source distribution (sdist)

Source distribution for flockfile 0.2.3
File Size Uploaded
flockfile-0.2.3.tar.gz 34.4 kB Details

Built distribution (wheel)

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

Total release size: 38.7 kB

Release files / flockfile-0.2.3.tar.gz

Download URL flockfile-0.2.3.tar.gz
Size 34.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bdd89568597a395fd2899399e0034f0ecb785f470991ec4b72d0e21365b496d2
BLAKE2b-256 checksum
How to use checksums
3ba209493e084ce3348dcd514ab90cbc5af119f59801a01879db6c7f81d58708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / flockfile-0.2.3-py3-none-any.whl

Download URL flockfile-0.2.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
185b14b7850b9a232336e78202819dcab48e60c0e8c2bd47a9a8e095606a09de
BLAKE2b-256 checksum
How to use checksums
320a304eef9b42a6bb092e4ddc0280670d32efeae127faacdb9eacf77fc913b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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