pyonce
Run code once! -- or once in a while...
def once(every: int = 0, key: Any = None) -> bool
Example
import pyonce
def update():
if pyonce.once(key='ONCE-001'):
print('global unique key')
if pyonce.once():
print('this is called from update')
if pyonce.once(every=5):
print('update() / 5')
for i in range(10):
if pyonce.once(every=2):
print(f'hello {i}')
update()
update()
output
hello 0
global unique key
this is called from update
update() / 5
this is called from update
update() / 5
hello 2
hello 4
update() / 5
update() / 5
hello 6
hello 8
The once() function relies on the traceback to derive the key.
A unique key corresponds to a unique state which is a simple counter.
When the counter hits zero the return value is True.
The first call for a key is always True.
Do not use it in production, such magic is pure evil.
Metadata
Release files for pyonce 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| pyonce-1.0.0.tar.gz | 2.7 kB | Without provenance | Details for pyonce-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyonce-1.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pyonce-1.0.0-py2.py3-none-any.whl |
Total release size: 5.6 kB
Release files / pyonce-1.0.0.tar.gz
| Download URL | pyonce-1.0.0.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9e311f28a7d274547ca986b034d75eebc5d269a23a946fe92200c3018562ceb
|
|
BLAKE2b-256 checksum How to use checksums |
c5c60472665661ec773cc7c672bd8b64426aa902d8e781c2b97e7e340a7a7eea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Release files / pyonce-1.0.0-py2.py3-none-any.whl
| Download URL | pyonce-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
274eab294bdf206aeca2db810dde9651c39bab9e0ce603960e4b6b7ed45fc009
|
|
BLAKE2b-256 checksum How to use checksums |
e1834319452be6f91cb36e9c47d22535a14dae8675eea9e637e892b987b192b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Security for pyonce 1.0.0
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.