minute和minutes、hour和hours、day和days、week和weeks也类似. unit in ( 'seconds', 'minutes', 'hours', 'days', 'weeks' ) self. _schedule_next_run () return ret def _schedule_next_run ( self ): assert self. info ( 'Running job %s ', self ) ret = self. start_day = None # Specific day of the week to start on def _lt_ ( self, other ): return self. period = None # timedelta between runs, only valid for self. next_run = None # datetime of the next run self. last_run = None # datetime of the last run self. at_time = None # optional time at which this job runs self. job_func = None # the job job_func to run self. interval = interval # pause interval * unit between runs self. next_run def idle_seconds ( self ): return ( self. cancel_job ( job ) def next_run ( self ): if not self. run () if isinstance ( ret, CancelJob ) or ret is CancelJob : self. append ( job ) return job def _run_job ( self, job ): ret = job. remove ( job ) except ValueError : pass def every ( self, interval = 1 ): job = Job ( interval ) self. jobs def cancel_job ( self, job ): try : self. sleep ( delay_seconds ) def clear ( self ): del self. _run_job ( job ) def run_all ( self, delay_seconds = 0 ): for job in self. should_run ) for job in sorted ( runnable_jobs ): self. jobs = def run_pending ( self ): runnable_jobs = ( job for job in self. Next event, the scheduler will simply fall behind.Class Scheduler ( object ): def _init_ ( self ): self. If a sequence of events takes longer to run than the time available before the If anĮxception is raised by action, the event will not be attempted in future calls Scheduler will maintain a consistent state and propagate the exception. (if any) and then return the deadline of the next scheduled call in theĮither action or delayfunc can raise an exception. If blocking is false executes the scheduled events due to expire soonest On until there are no more scheduled events. This method will wait (using the delayfuncįunction passed to the constructor) for the next event, then execute it and so Queue, this method will raise a ValueError. If event is not an event currently in the Return value is an event which may be used for later cancellation of the eventĬhanged in version 3.3: kwargs parameter was added. Kwargs is a dictionary holding the keyword arguments for action. A lower number represents a higher priority.Įxecuting the event means executing action(*argument, **kwargs).Īrgument is a sequence holding the positional arguments for action. With the return value of the timefunc function passed to the constructor.Įvents scheduled for the same time will be executed in the order of their The time argument should be a numeric type compatible enter ( 5, 1, print_time, kwargs = ) ¶ # despite having higher priority, 'keyword' runs after 'positional' as enter() is relative. enter ( 5, 2, print_time, argument = ( 'positional' ,)). sleep ) > def print_time ( a = 'default' ).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |