from datetime import datetime from apscheduler.scheduler import Scheduler import time def tick(): print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__': scheduler = Scheduler() scheduler.add_interval_job(tick, seconds=1) print('Press Ctrl+C to exit') scheduler.start() time.sleep(10)
每秒鐘執行一次tick函數, 在主進程中開線程函數