Wrapper for threading.Timer to allow resetting
Project description
resettabletimer
Wrapper for threading.Timer
to provide a resettable Timer implementation. Also provides fake timer for testing.
Usage
ResettableTimer
from resettabletimer import ResettableTimer
delay = 5 # seconds
function = print
# Create resettable timer
t = ResettableTimer(delay, function, ["Hello"], {"end":" timer!\n"})
# Starting and canceling work similarly than with threading.Timer
t.start()
# Wait 1-5 seconds
# Reset the timer
t.reset()
# Hello should be printed after five seconds
FakeTimer
from resettabletimer import FakeTimer
t = FakeTimer(2, print, ["Hello"], {"end":" timer!\n"})
# Starting and canceling work similarly than with threading.Timer
t.start()
# Wait >2 seconds
# Nothing happens
# Time passage is controlled with pass_time
t.pass_time(2)
# Hello should be printed
Testing
Check and automatically fix formatting with:
pycodestyle resettabletimer
autopep8 -aaar --in-place resettabletimer
Run static analysis with:
pylint -E --enable=invalid-name,unused-import,useless-object-inheritance resettabletimer
Run unit tests:
# Run unit tests
python3 -m unittest discover -s tst/
# Run unit tests with coverage analysis
coverage run \
--branch \
--source resettabletimer/ \
-m unittest discover -s tst/
coverage report -m
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
resettabletimer-1.0.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for resettabletimer-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37409ccb6899dc997d96e8692741af091880e172ac62724cf289e406d6d622d1 |
|
MD5 | 7137cc1cb678e7283cb251678e04c64a |
|
BLAKE2b-256 | 3cb2226feccd7832500924a1d378840c59d50d5b03bbe08869176e0158662750 |