【发布时间】:2019-01-29 03:48:01
【问题描述】:
我已经调整了这个基本示例来说明主题中的要点: https://github.com/agronholm/apscheduler/blob/master/examples/executors/processpool.py
这是调整后的代码(参见 args=[datetime.now()])
#!/usr/bin/env python
from datetime import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler
def tick(param):
print('Tick! The time is: %s' % param)
if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_executor('processpool')
scheduler.add_job(tick, 'interval', seconds=3, args=[datetime.now()])
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
pass
当我运行它时,输出时间戳不会更新:
$ ./test.py
Press Ctrl+C to exit
Tick! The time is: 2019-01-28 19:41:53.131599
Tick! The time is: 2019-01-28 19:41:53.131599
Tick! The time is: 2019-01-28 19:41:53.131599
这是预期的行为吗?我正在使用 Python 3.6.7 和 apscheduler 3.5.3,谢谢。
【问题讨论】: