3 ms·
Python threads: communication and stopping
- g3orge 15y agoI learn new things about Python every day.
- oconnore 15y agoThe "politely ask it to stop" paradigm is not a solution. For it to work, your thread cannot perform any blocking calls, nor can it call out to any long running functions that are not specifically designed to check a stop flag frequently.
- koenigdavidmj 15y agoYou can use os.pipe or socket.socketpair. That at least allows you to use blocking select, poll, or similar.
- eliben 15y agoYep, I explicitly mentioned this bit in the article. Then again, when your thread performs some long blocking call and you want to kill it, you're out of luck anyway. The advice in the post is directly applicable to problems where the blocking calls aren't particularly long.