Pychrono is a Python package for managing delays, scheduling tasks, and timing functions. It supports both synchronous and async operations, making time management simple and efficient.
Project description
Pychrono
Pychrono is a Python package designed for managing delays, scheduling tasks, timing functions, and more. It provides decorators for repeating tasks, scheduling actions, and running tasks asynchronously using threading. Pychrono simplifies time-related operations for both synchronous and asynchronous contexts.
Features
- Delay execution for a specific amount of time.
- Get the current system time and format it.
- Run tasks on a delay asynchronously.
- Repeat functions multiple times.
- Measure function execution time.
- Use a robust
Timer
class with start, pause, resume, and elapsed time tracking.
Installation
pip install pychrono
Usage
1. Delays and Time Functions
Delay Execution
import pychrono
# Delay execution for 1000 milliseconds (1 second)
pychrono.delay(1000)
Get Current Time
# Get the current time in seconds since the epoch
current_time = pychrono.current()
print(f"Current time: {current_time}")
Convert Time to Local String
# Convert time to a readable local time string
seconds = pychrono.current()
formatted_time = pychrono.local(seconds)
print(f"Local time: {formatted_time}")
2. Decorators
Repeat Function Execution
@pychrono.repeat(3)
def greet():
print("Hello!")
greet() # This will print "Hello!" three times
Time a Function's Execution
@pychrono.timer
def long_task():
for _ in range(1000000):
pass
# Print the time taken to run the function
long_task()
Asynchronous Scheduling with Delay
@pychrono.schedule(2000) # Delay for 2000 milliseconds (2 seconds)
def say_hello():
print("Hello after 2 seconds!")
say_hello() # Will print "Hello" after 2 seconds without blocking
Run a Function Asynchronously
@pychrono.asynchronous
def task():
print("Running asynchronously!")
task() # Runs in a separate thread
3. Timer Class
The Timer class allows you to start, pause, resume, and get the elapsed time. Printing the timer object directly will output the seconds elapsed.
Start, Pause, and Resume Timer
# Create a timer instance
timer = pychrono.Timer()
# Start the timer
timer.start()
# Perform some task
time.sleep(2)
# Get the elapsed time
print(f"Elapsed: {timer}") # Prints elapsed time in seconds (e.g., 2.0)
# Pause the timer
timer.pause()
# Resume the timer
timer.resume()
# Get updated elapsed time
time.sleep(1)
print(f"Updated Elapsed: {timer}") # Prints updated elapsed time (e.g., 3.0)
More Features Coming Soon!
Stay tuned for more functionalities such as:
- Recurring scheduled tasks.
- Enhanced threading control and task management.
- Time zone support for easier global time handling.
- And much more!
Feel free to contribute to the project, raise issues, or suggest features by visiting our GitHub repository.
License
Pychrono is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pychrono-0.1.0.tar.gz
.
File metadata
- Download URL: pychrono-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb6cb8286855ffed45856a07201870b57c45e87005daae48939985a3b4c2696 |
|
MD5 | dabff4d96a2bc6c69c708daf7283739d |
|
BLAKE2b-256 | e32251506422df201fabc04f71d2c7509d181032720776dbf869686b8ce4fc29 |
File details
Details for the file pychrono-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pychrono-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91451d232adf40e73c44b5d412f4aa394dc46382042b6b6e527134eb74c1c529 |
|
MD5 | fc70b677ff1fe960a6d358e2b98a6373 |
|
BLAKE2b-256 | 72038b3d26c07e2f4c755a4b1a24229dc587217cae70e77bf507605d77ce8d41 |