Schedule is a third-party lightweight task scheduling module that can execute times by seconds, minutes, hours, dates, or custom events. Implementing timed tasks with the scheduling module schedule Personal comment: better than threading.Timer, no need to call it in a loop. This function will wait (using the delayfunc() function passed to the constructor) and then execute the events until there are no more scheduled events. This method will run a ValueError if the event is not the one currently in the queue. cancel(event): removes an event from the queue.enter(delay, priority, action, argument), schedule an event to delay the delay by one time unit.run () if _name_ = "_main_" : loop_monitor () strftime ( '%Y-%m- %d %H:%M:%S' ) print ( 'do func time :', ts ) loop_monitor () def loop_monitor (): s = sched. Import datetime import time import sched def time_printer (): now = datetime. It also supports multi-threaded applications, where the delay function is called immediately after each task is executed to ensure that other threads can also execute.Ĭlass sched.scheduler(timefunc, delayfunc) This class defines a generic interface for scheduling events, it takes two external arguments, timefunc is a function that returns a number of time type without arguments (commonly used as time in the time module), delayfunc should be a function that takes one argument to call, is compatible with the output of timefunc, and serves to delay multiple time units (commonly used as sleep in the time module). The sched module implements a generic event scheduler that uses a delay function in the scheduler class to wait for a specific amount of time to execute a task. Note: Timer can only be executed once, here it needs to be called in a loop, otherwise it can only be executed once Implementing timed tasks with the built-in module sched start () if _name_ = "_main_" : loop_monitor () strftime ( '%Y-%m- %d %H:%M:%S' ) print ( 'do func time :', ts ) loop_monitor () def loop_monitor (): t = Timer ( 5, time_printer ) t. Import datetime from threading import Timer def time_printer (): now = datetime. job ( interval = timedelta ( seconds = 2 )) def sample_job_every_2s (): print "2s job current time : )
![python active timer modules python active timer modules](https://autogis-site.readthedocs.io/en/2019/_images/plugin_alkutila.png)
![python active timer modules python active timer modules](https://scrolltest.com/wp-content/uploads/2019/06/promode_dietmesh.jpg)
Import time from timeloop import Timeloop from datetime import timedelta tl = Timeloop ().