Skip to main content

A periodic timer that can be started multiple times

Project description

A pure-python periodic timer that can be started multiple times

Usage

$ pip install multitimer
import multitimer
import time

def job():
    print("I'm working...")

# This timer will run job() five times, one second apart
timer = multitimer.MultiTimer(interval=1, ontimeout=job, count=5)

# Pauses for one interval before starting job() five times
timer = multitimer.MultiTimer(interval=1, ontimeout=job, count=5, runonstart=False)


# You can specify input parameters for the ontimeout function
def job2(foo):
    print(foo)

timer = multitimer.MultiTimer(interval=1, ontimeout=job2, params={'foo':"I'm still working..."})

# Also, this timer would run indefinitely...
timer.start()

time.sleep(5)

# ...unless it gets stopped
timer.stop()


# If a mutable object is used to specify input parameters, it can be changed after starting the timer
output = {'foo':"Doin' my job again."}
timer = multitimer.MultiTimer(interval=1, ontimeout=job2, params=output, count=5)
timer.start()

time.sleep(3.5)
output['foo'] = "I'd like to be done now."

# And a MultiTimer can be re-started by just calling start() again
time.sleep(2)
output['foo'] = 'Please just let me be...'
timer.start()
time.sleep(4.5)
timer.stop()

Releases

0.1, 2018-02-15

  • Initial release

Meta

Josh Burnett - josh@burnettsonline.org

Distributed under the MIT license. See LICENSE.txt for more information.

https://github.com/joshburnett/multitimer

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

multitimer-0.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

multitimer-0.1-py2.py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page