Metadata-Version: 2.4
Name: simple-interval
Version: 0.1.3
Summary: 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.
Author-email: Heath Henley <heath.j.henley@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/heathhenley/simple-interval
Project-URL: Repository, https://github.com/heathhenley/simple-interval
Project-URL: Issues, https://github.com/heathhenley/simple-interval/issues
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Simple Interval

Using Python threading to run a function at a specific interval. This implementation is very similar to the [implementation](https://github.com/python/cpython/blob/22830103e598c63663b462c4e42b74e7a9d3bb99/Lib/threading.py#L1358) of [`threading.Timer`](https://docs.python.org/3/library/threading.html#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

```bash
uv add simple-interval
```
or 
```bash
pip install simple-interval
```

## Usage

```python
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)
```
