简体   繁体   中英

How to stop a thread and restart it - python

How can I stop a thread from running and then restart it when called, havent been able to get a solid answer on this. Thanks in advance.

According to this link , currently, [...], threads cannot be destroyed, stopped, suspended, resumed, or interrupted.

thread must terminate from the outside,Python doesn't give you this ability, and thus forces you to design your thread systems more carefully. This recipe is based on the idea of a thread whose main function uses a loop. Periodically, the loop checks if a threading.Event object has been set. If so, the thread terminates; otherwise, it waits for the object.

The answer is: You don't. Instead, you kindly ask it to go away. The thread must periodically check if it's been asked to go away and then comply (typically after some kind of clean-up)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM