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.5.tar.gz (3.7 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.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simple_interval-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f91acb5617e5ffc29ba65e64fdb164745d827fc754a9295b15596feea81cb439
MD5 50d32a508615f28afe7b2f966c26d42d
BLAKE2b-256 77e38de65b9efc091f873a21b0bc206f26505100d222f076ee4dcfcf689063c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_interval-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cf8461ef635f85b69d615cc80cbc320dd134fb1b55745e6603fcf984fc912b52
MD5 dfe804d1322ef90870479da98f03eeb4
BLAKE2b-256 056e953889c3546e5d718ee5926f19d028848dd3475f816f57ade12480c8bbaa

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