Context managers that enforce a minimum cool-down interval between consecutive blocks (sync and asyncio).
Project description
cooltime-guard
A micro library to guard execution with a cooldown interval.
It ensures that a block of code runs only after a specified minimum time has passed since the previous execution.
If not enough time has passed, it waits (time.sleep) automatically before running.
Features
- Simple and lightweight
- Context manager support with with syntax
- Guarantees a minimum interval between executions
- Useful for hardware control, API calls, or any resource that needs cooldown
Examples
A simple example:
import time
import cooltime_guard
# create a guard with 5ms interval
guard = cooltime_guard.Guard(interval=0.005)
def f():
start = time.time()
with guard:
# ... Access to resources requiring a 5ms cooldown ...
return time.time() - start
print(f()) #=> Nearly 0
print(f()) #=> Nearly 0.005
print(f()) #=> Nearly 0.005
time.sleep(0.01)
print(f()) #=> Nearly 0
When controlling LEDs that require a minimum interval of 1ms to light up properly:
import cooltime_guard
# create a guard with 5ms interval
cg = cooltime_guard.Guard(interval=0.005)
def led_flash():
with cg:
GPIO.Pin(15).flash()
Use cases
- Hardware access that requires cooldown (e.g., LEDs, sensors, actuators)
- API clients that must avoid calling too frequently
- Rate-limiting function calls without complex frameworks
Notes
Guarddoes not perform lock control for threading/multiprocessing. Therefore, if code blocks execute in parallel, the intended behavior may not occur. In such cases, use locks in conjunction with guards.
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cooltime_guard-0.1.0.tar.gz.
File metadata
- Download URL: cooltime_guard-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd1744dae0cd8440db89f8afd1fb4e2ce61131aeec4d68c484d42a579f58bfd7
|
|
| MD5 |
5b1b7500ec2fd9cd1c9785387a720cdf
|
|
| BLAKE2b-256 |
2848bef358fe476d492f6c2373499f53af7672e6d0d8c52f885d39a9c4784691
|
Provenance
The following attestation bundles were made for cooltime_guard-0.1.0.tar.gz:
Publisher:
python-publish.yml on nakat-t/cooltime-guard-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cooltime_guard-0.1.0.tar.gz -
Subject digest:
bd1744dae0cd8440db89f8afd1fb4e2ce61131aeec4d68c484d42a579f58bfd7 - Sigstore transparency entry: 569900938
- Sigstore integration time:
-
Permalink:
nakat-t/cooltime-guard-py@c6fb9d5e5c15ff9563ad6de6c396f01b95f3e994 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nakat-t
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6fb9d5e5c15ff9563ad6de6c396f01b95f3e994 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cooltime_guard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cooltime_guard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfbb2949b395a601418036bea76f69c102710d9fe94d04c4f36b6ba0f9b1be63
|
|
| MD5 |
cee5e70e20b58dc1585c678e8ab8c09b
|
|
| BLAKE2b-256 |
7ca84a2b0fdd1d28adb541cc5a181d5cb29f068bdfc9a1ed1a1baad8176f7472
|
Provenance
The following attestation bundles were made for cooltime_guard-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on nakat-t/cooltime-guard-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cooltime_guard-0.1.0-py3-none-any.whl -
Subject digest:
bfbb2949b395a601418036bea76f69c102710d9fe94d04c4f36b6ba0f9b1be63 - Sigstore transparency entry: 569900941
- Sigstore integration time:
-
Permalink:
nakat-t/cooltime-guard-py@c6fb9d5e5c15ff9563ad6de6c396f01b95f3e994 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nakat-t
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6fb9d5e5c15ff9563ad6de6c396f01b95f3e994 -
Trigger Event:
release
-
Statement type: