Twisted Apscheduler 使用


from datetime import datetime
import os

from twisted.internet import reactor
from apscheduler.schedulers.twisted import TwistedScheduler


def tick():
    print('Tick! The time is: %s' % datetime.now())


if __name__ == '__main__':
    scheduler = TwistedScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

    # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
    try:
        reactor.run()
    except (KeyboardInterrupt, SystemExit):
        pass

Twisted as a server-side tcp concurrency often needs some timers to process some things. In general, we can use CallLater to only perform timer functions, but using the task scheduling framework can achieve some routine work, such as timing Generate twisted information about the currently connected client

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325562518&siteId=291194637