[Newbie] How to wait for asyncronous input
steve+comp.lang.python at pearwood.info
Sat Aug 11 11:56:30 CEST 2012
On Sat, 11 Aug 2012 11:24:48 +0200, Hans Mulder wrote:
> On 11/08/12 09:07:51, pozz wrote:
>> When the main thread wants to close the serial port, the receiving
>> thread can be killed
> How would you do that?
> IFAIK, there is no way in Python to kill a thread.
> The usual work-around is to have a global flag that you'd set to True
> when the main thread wants to close the port. The read would have a
> timeout of 1 second of so, so that the reading thread is woken up every
> second, so it can check that flag and wind up when the flag is set.
It doesn't need to be a global flag. You can make the flag an attribute
of the thread, and then have the thread check self.flag.
More information about the Python-list