Skip to main content

Allow a task to be executed regulary

Project description

GitHub GitHub tag (latest by date) GitHub Release Date GitHub last commit GitHub issues Python version

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

CyclicTask-0.1.4.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

CyclicTask-0.1.4-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

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