Related To Threads

S

Sidd

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.
 
S

Steve Holden

Sidd said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top