Skip to content

heathhenley/simple-interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages