Skip to main 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. Whether you need to benchmark performance or execute actions at specific intervals, Ptymer provides a simple and efficient solution

Project description

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 or higher. To install, use 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.

Project details


Download files

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

Source Distribution

ptymer-0.0.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

ptymer-0.0.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file ptymer-0.0.1.tar.gz.

File metadata

  • Download URL: ptymer-0.0.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for ptymer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9285d4a38b537fb9307b373c346a7cbcb8296a2355b7ad54a29ab185c44f5ffd
MD5 ac3f3142738f7f3c2e44a19af4876264
BLAKE2b-256 e3fc46e0ed50c36329934001b2bcb8b319804974e56a5903ec1efa37516e40af

See more details on using hashes here.

File details

Details for the file ptymer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ptymer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for ptymer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d2bec344c2e175df3da32643ee104e625dd10046dcfad16f69ee1276194692b
MD5 c5e169572cc8a9b8c2f3345c56f86515
BLAKE2b-256 a8b1a140c83c45c463de2fc3e2487b46eee886ecffa9e5fd5330bd3d743933bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page