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 implemention of threading.Timer in Python - 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.1.tar.gz (3.3 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.1-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simple_interval-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b83ef7b174f7566bf50b4525889c0c27eab9d810f9e2fcbafabfafc49c482899
MD5 66b781f8bbfc09467b0293d94693af52
BLAKE2b-256 e3c44acd71962e2fb9e061f3a5eb05ba3afdae335a9863a4de898a762acaace4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_interval-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e47fe09ed2087fc9077e30f304f2d7dc5ba4974dd7c154bac3e93bc7f616d248
MD5 8a7b3346ebac114d0c6f25bbf7c868aa
BLAKE2b-256 40774eda5e569b6aa14991cf2acb49a06481315ee113c3b4ad06a7fd66a3d6cb

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