Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
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()
3534569
>>> # Close enough, that's 3.534569 seconds
>>> t.elapsed
3534569

For an idea of how this works, check out the source code and/or read http://msdn.microsoft.com/en-us/magazine/cc163996.aspx. 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 https://bitbucket.org/briancurtin/timer.

Release History

Release History

This version
History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
timer-0.1.win32-py2.6.exe (207.0 kB) Copy SHA256 Checksum SHA256 2.6 Windows Installer Feb 17, 2011
timer-0.1.win32-py2.7.exe (207.0 kB) Copy SHA256 Checksum SHA256 2.7 Windows Installer Feb 17, 2011
timer-0.1.win32-py3.1.exe (207.0 kB) Copy SHA256 Checksum SHA256 3.1 Windows Installer Feb 17, 2011
timer-0.1.win32-py3.2.exe (207.0 kB) Copy SHA256 Checksum SHA256 3.2 Windows Installer Feb 17, 2011
timer-0.1.zip (9.9 kB) Copy SHA256 Checksum SHA256 Source Feb 16, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting