[Tutor] Cancelling a thread or blocked read

Christopher Arndt chris.arndt at web.de
Sat Mar 31 18:18:38 CEST 2007


Dhiraj Sharma schrieb:
> 1. Is it possible to cancel (kill) a "child" thread from the main thread
> in Python running on Windows?

If you have control over the code of the thread, it could periodically check
(in it's "run" method) an Event or Queue object, whether it should exit. See
http://www.python.org/doc/current/lib/event-objects.html

> 2. Also, is it possible to cancel (abort) a blocking read (say, to
> stdin) in a function that can be called by a timer? The goal is to
> cancel the read if input is not forthcoming within a specified time.

Under Unix-like systems I'd use the "select" module
(http://www.python.org/doc/current/lib/module-select.html), but under Windows
this only works for sockets.

Chris


More information about the Tutor mailing list