Related To Threads

Steve Holden steve at holdenweb.com
Sun Aug 21 18:20:58 EDT 2005


Sidd wrote:
> Hello,
>       I want to write a thread in python which can be invoked for say 5
> sec, within that the threads function would be to take input,is it
> possible because i tried it and found that raw_input() is blocking
> threads.
> 
There isn't really a convenient solution to this problem, since a thread 
can't easily be stopped "from the outside".

Various solutions you might dream up using signals are likely to be 
either unreliable or non-portable or possibly both.

You m ay have to poll the keyboard directly to gather input and time out 
if it doesn't arrive.

http://www.python.org/doc/faq/windows.html#how-do-i-check-for-a-keypress-without-blocking

will be some help in the windows environment, select() is your friend 
under *nix.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/




More information about the Python-list mailing list