GithubHelp home page GithubHelp logo

apgeorg / thym Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 8 KB

Bundle of timing utilities

License: MIT License

Python 100.00%
timer timer-functions elapsed-time remaining-time timeout python callback threading pip pypi-package

thym's Introduction

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.

thym's People

Contributors

apgeorg avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.