Skip to main content

Bundle of timing utilities such as Timer, Stopwatch, etc.

Project description

thym PyPI version

Bundle of timing utilities such as Timer that allows you to trigger an event at a specified interval or Stopwatch to measure time etc.

Installation

There are two ways to install thym:

Install thym from PyPI (recommended):

sudo pip install thym

If you are using a virtualenv, you may want to avoid using sudo:

pip install thym

Alternatively: install thym from the GitHub source:

First, clone thym using git:

git clone https://github.com/apgeorg/thym.git

Then, cd to the thym folder and run the install command:

cd thym
sudo python setup.py install

Getting started

Timer

Timer is able to trigger a callback either periodically or as a one shot by setting the oneshot argument correspondingly. There is an elapsed property that returns the elapsed time since start() was called. Further, a remaining property is also available that returns the remaining time of the specified interval.

import thym

# Timer callback function
def timer_timeout():
  print("Timeout!")

# Create a Timer which runs periodically 
t = thym.Timer(1, timer_timeout, oneshot=False)

# Start running
t.start()

A running Timer can be stopped anytime by calling stop() as shown below. The elapsed time and remaining time are calculated accordingly.

t.stop()

Stopwatch

Stopwatch triggers a callback when stop() is called. The callback can be passed over the Stopwatch consturctor.
There is an elapsed property that returns the elapsed time since start() was called.

import thym

# Stopwatch callback function
def stopped_callback():
  print("Stopwatch stopped!")

# Create a Stopwatch 
sw = thym.Stopwatch(stopped_callback)

# Start running
sw.start()

A running Stopwach can be stopped anytime by calling stop() as shown below. Accordingly, the elapsed time is calculated.

sw.stop()

Licence

Thym is licensed under MIT. See LICENSE file for details.

Copyright © 2019 Apostolos Georgiadis.

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 thym, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size thym-0.0.3-py3-none-any.whl (5.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size thym-0.0.3.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

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