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.
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
The Timer class is used to measure the execution time of code snippets. It can be instantiated in several ways:
from ptymer import Timer
tm = Timer().start()
# Your code here
tm.stop()
from ptymer import Timer
with Timer() as tm:
# Your code here
from ptymer import Timer
@Timer()
def your_function_here():
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.
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()
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.
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.
This project is licensed under the MIT License. See the LICENSE file for more details.