https://github.com/trypsynth/repeating_timer
Run a function over and over in a thread.
https://github.com/trypsynth/repeating_timer
Last synced: over 1 year ago
JSON representation
Run a function over and over in a thread.
- Host: GitHub
- URL: https://github.com/trypsynth/repeating_timer
- Owner: trypsynth
- License: mit
- Created: 2021-10-05T18:24:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-21T17:43:55.000Z (over 4 years ago)
- Last Synced: 2025-02-26T20:19:13.105Z (over 1 year ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# repeating_timer
Run a function over and over in a thread.
## Why?
A package from [Q-continuum](http://hg.q-continuum.net) (with the same name) claims to provide this functionality. However, it no longer works in python 3. This project is a complete rewrite that works with Python 3, and aims to have more features.
## Usage.
```python
import time
from repeating_timer import RepeatingTimer
t = RepeatingTimer(1.0, print, "Hi.")
t.start()
time.sleep(5)
t.stop()
```
This will print "Hi." every second for five seconds, then it will exit. You'll notice that the time.sleep() doesn't interfeer with the timer at all, because it's threaded. That's the beauty of it!
## Note.
If you pass a function that takes time to execute, this time won't be taken away from how long you have until the next time the function is called.