我有一个来自sched模块的 python 计划,我想在一个单独的线程中执行,同时能够随时停止它。我看了看,threading module但不知道哪种方法是实现这一点的最佳方法。
时间表示例:
>>> s.run()
one
two
three
end
线程中的调度示例:
>>> t = threading.Thread(target = s.run)
>>> t.start()
one
two
>>> print("ok")
ok
three
end
>>>
想要的结果:
>>> u = stoppable_schedule(s.run)
>>> u.start()
>>>
one
two
>>> u.stop()
"schedule stopped"
DIEA
相关分类