Allow a task to be executed regulary
Project description
CyclicTask
Allow a task to be executed regulary
Table of content
Installation
python3 -m pip install CyclicTask
ContinuousTask class usage
Minimum usage
The ContinuousTask class allow to execute a task as fast as possible, until the stop request.
from CyclicTask.ContinuousTask import ContinuousTask
# Sub-classing `ContinuousTask` class
class Task(ContinuousTask):
# override `task` function
def task(self) -> None:
# --- Task definition ---
pass
# Task creation
task = Task()
# Task start
task.start()
# Task stop
task.stop()
# Waiting for the end of the current cycle
task.join()
Maximum execution time
maximumTime parameter allow to monitor the execution duration of one cycle.
If this one exceed 80% of maximumTime the attribut cycleTimeWarning is set for one cycle, and a message in the logger is written.
If the duration exceed maximumTime the exception CycleTimeError is raised, and a message is written in the logger.
from CyclicTask.ContinuousTask import ContinuousTask
# Sub-classing `ContinuousTask` class
class Task(ContinuousTask):
# override `task` function
def task(self) -> None:
# --- Task definition ---
pass
# Task creation with `maximumTime` set to 1 second
task = Task(maximumTime = 1.0)
# Task start
task.start()
# Task stop
task.stop()
# Waiting for the end of the current cycle
task.join()
TimedTask class
Minimum usage
The TimedTask class allow to execute a task every x seconds, until the stop request.
from CyclicTask.TimedTask import TimedTask
# Sub-classing `TimedTask` class
class Task(TimedTask):
# override `task` function
def task(task) -> None:
# --- Task definition ---
pass
# Task creation with `cycleTime` set to 1 second
task = Task(cycleTime = 1.0)
# Task start
task.start()
# Task stop
task.stop()
# Waiting for the end of the current cycle
task.join()
Maximum execution time
maximumTime parameter allow to monitor the execution duration of one cycle.
If maximumTime is left to None, the maximum execution time is set to 150% of the cycle time.
If this one exceed 80% of maximumTime the attribut cycleTimeWarning is set for one cycle, and a message in the logger is written.
If the duration exceed maximumTime the exception CycleTimeError is raised, and a message is written in the logger.
from CyclicTask.TimedTask import TimedTask
# Sub-classing `TimedTask` class
class Task(TimedTask):
# override `task` function
def task(task) -> None:
# --- Task definition ---
pass
# Task creation with `cycleTime` set to 1 second, and `maximumTime` set to 1.0 second
task = Task(cycleTime = 1.0, maximumTime = 1.0)
# Task start
task.start()
# Task stop
task.stop()
# Waiting for the end of the current cycle
task.join()
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file CyclicTask-0.1.4.tar.gz.
File metadata
- Download URL: CyclicTask-0.1.4.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99b73285cc2fa078957de43695a43ae528053bc96c4310a2c182975374234143
|
|
| MD5 |
b8497e7426d8f1ac3edcfe589356a6b9
|
|
| BLAKE2b-256 |
85e24f7f6fc3757529fa120f0f8b530d9259631fcb7d38d2d24b113952852962
|
File details
Details for the file CyclicTask-0.1.4-py3-none-any.whl.
File metadata
- Download URL: CyclicTask-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ddf515e2c8c0d0592ac30d73bd292d7627bf5d150f77221118024c14e577214
|
|
| MD5 |
c7295835b69bfd785b6892c1ff97f9f1
|
|
| BLAKE2b-256 |
031b226cb03b658782fa4877099c2c9f10a945d179571dadd0eb0bdc882dac31
|