sing
Ensure a single process is running. Using lockfile and process checking.
Why?
Sometime you want that a process runs at most once, for example a scheduled cron job that should always finish before starting again. That was my case.
Install
pip install sing
Examples
Normally, at the beginning of the file, you may want to declare, that you want to be the single instance:
from sing import single
assert single()
That’s it, for most of the use case, you don’t need anything else. The assert will fail if the lock is already taken.
This uses a pid lockfile, in a temporary folder to ensure this. More on that in sing.py
You may want to grant all the lock from the same process, in that case you’ll need.
assert single(allow_all_from_this_process=True)
You may have different subsections, and you want to have different locks, even if you’re on the same process, both of them will return True:
single(flavor='first')
single(flavor='second')
Finally, if a PID file is there, but the process died, you may want to grant the lock. Use the ensure_process_running to check it.
Notes
Free software: MIT license
Documentation: https://python-sing.readthedocs.io.
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Lot of inspiration comes from pycontribs/tendo that serves the same purpose. I needed PID file, and allow same process grants, so I made this package.
History
0.1.0 (2018-02-25)
First release on PyPI.
Metadata
Release files for sing 0.1.5
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 | Actions |
|---|---|---|---|---|
| sing-0.1.5.tar.gz | 11.6 kB | Without provenance | Details for sing-0.1.5.tar.gz |
Release files / sing-0.1.5.tar.gz
| Download URL | sing-0.1.5.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0c79093e57c08dedd93a2f1735b2e21d5515b3ba0312f2daa0fc0a696d79d50
|
|
BLAKE2b-256 checksum How to use checksums |
b2b528c3191b15f05ec987c8516a9a7f534496c164be935012df794c680eea81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0
|
Security for sing 0.1.5
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.