AP scheduler


Twisted 和 AP scheduler一起用的第一个例子


from twisted.application.service import Application
from twisted.application.service import Service
from apscheduler.schedulers.twisted import TwistedScheduler
from apscheduler.triggers.interval import IntervalTrigger

class ScheduleService(Service):

    def test(self):
        print "Hello world !"

    def __init__(self):
        self.scheduler = TwistedScheduler()
        self.trigger = IntervalTrigger(seconds=5)


    def startService(self):
        self.scheduler.add_job(self.test, self.trigger)
        self.scheduler.start()

    def stopService(self):
        print "service shut down"
        self.scheduler.shutdown()

app = Application("MyApp")
schedule_service = ScheduleService()
schedule_service.setServiceParent(app)

application = app


你可能感兴趣的:(AP,twisted)