Skip to content

Scheduler class

Taipy Scheduler.

A scheduler for periodic methods that lets you run Taipy functions (or any other Python callable) periodically at pre-determined intervals using a simple, human-friendly syntax.

Features:

  • A simple-to-use API for scheduling methods.
  • Run pending methods on the background thread.
  • Allow to schedule methods by seconds, minutes, hours, days, weeks, months, or even years.
  • Allow to schedule methods to run at a specific time on a specific date.
  • Allow to stop the schedule until a certain time.

Usage:

import taipy as tp
from taipy import Config, Scheduler

if __name__ == "__main__":
    # Configure your Taipy application
    ...
    my_scenario_config = Config.configure_scenario("my_scenario", [task_config])

    # Schedule creating a scenario every 10 minutes
    Scheduler.every(10).minutes.do(tp.create_scenario, my_scenario_config)

    # Schedule creating and submitting a scenario every day at 10:30
    Scheduler.every().day.at("10:30").do_create_and_submit_scenario(my_scenario_config)

    Scheduler.start()

    # Do other stuff...

    Scheduler.stop()

Methods

cancel_scheduled_method() classmethod

cancel_scheduled_method(scheduled_method: ScheduledMethod)

Cancel a scheduled method.

Parameters:

Name Type Description Default

scheduled_method

ScheduledMethod

The scheduled method to be unscheduled.

required

clear() classmethod

clear(tag: Optional[Hashable] = None)

Gets scheduled methods marked with the given tag, or all methods if tag is omitted.

Parameters:

Name Type Description Default

tag

Optional[Hashable]

An identifier used to identify a subset of scheduled methods to retrieve.

None

every() classmethod

every(interval: int = 1) -> ScheduledMethod

Schedule a new periodic method.

Parameters:

Name Type Description Default

interval

int

A quantity of a certain time unit. Defaults to 1.

1

Returns:

Name Type Description
ScheduledMethod ScheduledMethod

An un-configured ScheduledMethod object.

get_scheduled_methods() classmethod

get_scheduled_methods(
    tag: Optional[Hashable] = None,
) -> List[ScheduledMethod]

Gets scheduled methods marked with the given tag, or all methods if tag is omitted.

Parameters:

Name Type Description Default

tag

Optional[Hashable]

An identifier used to identify a subset of methods to retrieve.

None

next_run() classmethod

next_run(
    tag: Optional[Hashable] = None,
) -> Optional[datetime.datetime]

Datetime when the next method should run.

Parameters:

Name Type Description Default

tag

Optional[Hashable]

Filter the next run for the given tag parameter.

None

start() classmethod

start(interval: float = 60)

Start the scheduler in a new thread. Pending scheduled methods are executed at each elapsed time interval.

Parameters:

Name Type Description Default

interval

float

Time to wait between each check, in seconds. Defaults to 60.

60
Note

It is intended behavior that run_continuously() does not run missed methods. For example, if you've registered a method that should run every minute and you set a continuous run interval of one hour then your method won't be run 60 time at each interval but only once.

stop() classmethod

stop(wait: bool = True, timeout: Optional[float] = None)

Stop the scheduler.

Parameters:

Name Type Description Default

wait

bool

If True, the method will wait for the scheduler to stop.

True

timeout

Optional[float]

The maximum time to wait. If None, the method will wait indefinitely.

None