Skip to content

PTymer is a lightweight Python package designed to help developers manage and monitor the execution time of their code. With features like timers and countdowns, it allows you to precisely measure runtime durations and set time-based triggers.

License

Notifications You must be signed in to change notification settings

hyskoniho/ptymer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PTymer ⏱️



           

PTymer is a Python project that provides insights and actions within the execution of code in a time context. This package includes three main classes: Timer, HourGlass, and Alarm, each with specific functionalities for time monitoring and control. You can find the full description in the Wiki Page.

Index

Installation

PTymer is compatible with Python 3.8 and later versions, and is officially available on PyPI. You can install it using pip:

pip install ptymer

Usage

Timer

The Timer class is used to measure the execution time of code snippets. It can be instantiated in several ways:

Normal Instance
from ptymer import Timer

tm = Timer().start()
# Your code here
tm.stop()
Context Manager
from ptymer import Timer

with Timer() as tm:
    # Your code here
Decorator
from ptymer import Timer

@Timer()
def your_function_here():

HourGlass

The HourGlass class is used to create a countdown timer. After the countdown finishes, it executes a user-defined function.

from ptymer import HourGlass

hg = HourGlass(seconds=5, visibility=True, target=print, args=("Hello World",)).start()

Note: In the arguments tuple, you need to put a comma at the end to identify it as a tuple if there's only one element.

Alarm

The Alarm class takes a list of times and a function. When the algorithm identifies that it has reached one of the times, it executes the defined function.

from ptymer import Alarm

alarm = Alarm(schedules=["10:49:00"], target=target, args=(), visibility=True).start()



⚠️ WARNING!

Due to multiprocessing, it's highly recommended that you safeguard the execution of the main process, when using HourGlass and/or Alarm instance, with the following statement before your code:

if __name__ == '__main__':
    # your code here

Some sample usage:

def foo():
    return True

if __name__ == '__main__':
    foo()

You can find more information about this issue here.

Contribution

Contributions are welcome!!! Feel free to open issues and pull requests on the GitHub repository. Pay attention to the test files content and don't forget to document every change! We use Pytest and there's a workflow set up on GitHub Actions that you might want to check out.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

PTymer is a lightweight Python package designed to help developers manage and monitor the execution time of their code. With features like timers and countdowns, it allows you to precisely measure runtime durations and set time-based triggers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages