Skip to main content

Wrapper for threading.Timer to allow resetting

Project description

resettabletimer

Build Status

Wrapper for threading.Timer to provide a resettable Timer implementation. Also provides fake timer for testing.

Usage

ResettableTimer

# If using python 2, import print function
from __future__ import print_function

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

# If using python 2, import print function
from __future__ import print_function

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

Run unit tests with command:

cd resettabletimer

python3 -m unittest discover -s tst/

Get test coverage with commands:

cd resettabletimer

coverage run -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.

Files for resettabletimer, version 0.7.0
Filename, size File type Python version Upload date Hashes
Filename, size resettabletimer-0.7.0.tar.gz (2.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page