Skip to main content

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

simple_interval-0.1.4.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_interval-0.1.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file simple_interval-0.1.4.tar.gz.

File metadata

  • Download URL: simple_interval-0.1.4.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for simple_interval-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9260a02ba813ad7ddaa446870bded287831a33a727b0c7a4abcc1b1ae3e92d0e
MD5 fb122bccb5514ae0750ef00010b8ac1f
BLAKE2b-256 c77a9a3dcf6714fffc6079cceaf118d18228baaee0748637cd2c46dac26ad08d

See more details on using hashes here.

File details

Details for the file simple_interval-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_interval-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 43d95954f28e08107a0818844811d60a7e70653b0ab5ed45f6d80eaf57ee72f0
MD5 ee5441e0bca7dda86a493e7206fe1243
BLAKE2b-256 3e15db0e6e192a478377334cea900d450a318178300781398406c9487dce2782

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page