Using Python threading to run a function at a specific interval. This implementation is very similar to the implemention of threading.Timer in Python - just runs on an interval instead of single time.
Project description
Simple Interval
Using Python threading to run a function at a specific interval. This implementation is very similar to the implementation of threading.Timer in CPython - it just runs on an interval instead of single time.
It does not account for how long the function takes to run - so it's an approximate interval and will wait the full interval from when the function ends to run again. This is different from the JavaScript implementation of setInterval for example, where the function is called on the tick and can result in multiple overlapping calls.
It works like that because that's what I needed for my use case.
Installation
uv add simple-interval
or
pip install simple-interval
Usage
import time
from simple_interval import set_interval
def print_hello():
print("Hello, world!")
interval = set_interval(print_hello, 1.0)
try:
while True:
# Do other stuff...
time.sleep(0.1)
except KeyboardInterrupt:
# Stop the interval
clear_interval(interval)
Project details
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 simple_interval-0.1.3.tar.gz.
File metadata
- Download URL: simple_interval-0.1.3.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23317fe320ed5e444f3899e68e33f7a0d38effa0b89ed270118cb4a70160b38b
|
|
| MD5 |
60d0c14976b9eee5da2a5bfb77a0953d
|
|
| BLAKE2b-256 |
308d68b0bd7c070a24539ae615cb633308aef3cda98ccd8db2403df4df0f3fde
|
File details
Details for the file simple_interval-0.1.3-py3-none-any.whl.
File metadata
- Download URL: simple_interval-0.1.3-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7302a9ac04c36e9febb9a2f59d7a2419ef6814c2c95456990d6ab4e76c0302fd
|
|
| MD5 |
9e080c667e4719785c13f9532c7ec81e
|
|
| BLAKE2b-256 |
c907e491562c61bc80b46b8515fd6a0c22c9729e9719a6d63ce35c3d9b0cc3f0
|