I have a repeated python schedule task as following,which need to run getMyStock() every 3 minutes in startMonitor():
from stocktrace.util import settings
import time, os, sys, sched
schedule = sched.scheduler(time.time, time.sleep)
def periodic(scheduler, interval, action, actionargs=()):
scheduler.enter(interval, 1, periodic,
(scheduler, interval, action, actionargs))
action(*actionargs)
def startMonitor():
from stocktrace.parse.sinaparser import getMyStock
periodic(schedule, settings.POLLING_INTERVAL, getMyStock)
schedule.run( )
The questions are:
1.how could i cancel or stop the schedule when some user event comes?
2.Is there any other python module for better repeated scheduling?Just like java quartz?
Q1:
scheduler.enterreturns the event object that is scheduled, so keep a handle on that and you cancancelit:I’ve moved your code into a class to make referring to the event more convenient.
Q2 is outside of the scope of this site.