To execute a function every x minutes: sched or threading.Timer?

北城余情 提交于 2019-12-05 04:10:27

It's not safe in Python 2 - Python 3.2:

From the Python 2.7 sched documentation:

In multi-threaded environments, the scheduler class has limitations with respect to thread-safety, inability to insert a new task before the one currently pending in a running scheduler, and holding up the main thread until the event queue is empty. Instead, the preferred approach is to use the threading.Timer class instead.

From the latest Python 3 sched documentation

Changed in version 3.3: scheduler class can be safely used in multi-threaded environments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!