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.3.tar.gz (3.5 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.3-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

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

Hashes for simple_interval-0.1.3.tar.gz
Algorithm Hash digest
SHA256 23317fe320ed5e444f3899e68e33f7a0d38effa0b89ed270118cb4a70160b38b
MD5 60d0c14976b9eee5da2a5bfb77a0953d
BLAKE2b-256 308d68b0bd7c070a24539ae615cb633308aef3cda98ccd8db2403df4df0f3fde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_interval-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7302a9ac04c36e9febb9a2f59d7a2419ef6814c2c95456990d6ab4e76c0302fd
MD5 9e080c667e4719785c13f9532c7ec81e
BLAKE2b-256 c907e491562c61bc80b46b8515fd6a0c22c9729e9719a6d63ce35c3d9b0cc3f0

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