Can I set timeout for the sys.stdin.readline() ?

Y

ywzhan

Hi, I am new here.
When I use sys.stdin.readline() to get input string from user,
how can I set a timeout value for this operation?
thank you.
 
J

Jay Parlar

Hi, I am new here.
When I use sys.stdin.readline() to get input string from user,
how can I set a timeout value for this operation?
thank you.

You can do a select() on sys.stdin, and put a timeout on the select, ie:

rfds, wfds, efds = select.select( [sys.stdin], [], [], 5)

would give you a five second timeout. If the timeout expired, then rfds
would be an empty list. If the user entered something within five
seconds, then rfds will be a list containing sys.stdin.

Note that by "user entered something", I mean they pressed
Enter/Return. The select will not exit if they just enter other text.

Jay P.
 
D

Dennis Lee Bieber

You can do a select() on sys.stdin, and put a timeout on the select, ie:

rfds, wfds, efds = select.select( [sys.stdin], [], [], 5)
To my knowledge, this won't work on M$ Windows (which the original
poster's headers seem to imply)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top