Skip to main content
Help us improve Python packaging – donate today!

High frequency start/stop timer

Project Description

timer is a C extension that provides a Timer class that operates similar to the threading module’s Timer factory. Provided a duration in microseconds and a callable, the timer can be constructed and started.:

>>> callback = lambda: print("Time up!")
>>> t = timer.Timer(1000000, callback) # One second timer
>>> t.start()
Time up!

Timer objects can also be constructed with optional arguments and keyword arguments to be passed to the callback.:

>>> def callback(*args, **kwargs):
...     print(args, kwargs)
>>> t = timer.Timer(1000000, callback, 1, 2, 3, hurf="durf")
>>> t.start()
(1, 2, 3) {'hurf': 'durf'}

Timer objects provide microsecond resolution when stopped. The value is returned from the stop method, and also available in the elapsed attribute.:

>>> t = timer.Timer(10000000, callback) # Ten second timer
>>> t.start()
>>> # Call stop after about three seconds
>>> t.stop()
>>> # Close enough, that's 3.534569 seconds
>>> t.elapsed

For an idea of how this works, check out the source code and/or read A number of Win32 APIs are used to supplement QueryPerformanceCounter to keep the timing high resolution and accurate.

This is fairly stable but doesn’t have a lot of tests and hasn’t been used all that much. I’ve tested it on Python 3.1 and backported it to work with Python 2.7. It probably works from other versions but I haven’t tried.

Development occurs at

Release history Release notifications

This version
History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
timer-0.1.win32-py2.6.exe (207.0 kB) Copy SHA256 hash SHA256 Windows Installer 2.6 Feb 17, 2011
timer-0.1.win32-py2.7.exe (207.0 kB) Copy SHA256 hash SHA256 Windows Installer 2.7 Feb 17, 2011
timer-0.1.win32-py3.1.exe (207.0 kB) Copy SHA256 hash SHA256 Windows Installer 3.1 Feb 17, 2011
timer-0.1.win32-py3.2.exe (207.0 kB) Copy SHA256 hash SHA256 Windows Installer 3.2 Feb 17, 2011 (9.9 kB) Copy SHA256 hash SHA256 Source None Feb 16, 2011

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page