473,626 Members | 3,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jun 10 '06 #1
1 11147

On Jun 10, 2006, at 5:14 AM, ywzhan wrote:
Hi, I am new here.
When I use sys.stdin.readl ine() 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.

Jun 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
53292
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
0
2390
by: Brano Zarnovican | last post by:
Hi ! I'd like to init curses and still have working Python interactive command line. I found that you can replace stdin/stdout/stderr like this: #!/usr/bin/python -i import curses import sys
0
1522
by: Tarek Ziadé | last post by:
Hello, I cannot manage to use socket timeouts with an imap ssl connector,and i badly *need* it :'( I have already mentionned it here: http://archives.free.net.ph/message/20050620.151244.e5390efe.en.html Does anyone have a solution ?
11
20900
by: William Stacey [MVP] | last post by:
Trying to test a simple console app that reads from standard in if you pipe input into it like: "c:\ type config.txt | consoleinput.exe" Seem to run into an issue. It seems like if you use a pipe, you can read all the input lines fine until eof. However, if you need to then prompt for input, the pipe is still hooked up so Read or ReadLine returns with -1 or null after that point. So you can't prompt for "Hit a key to continue", etc....
6
2757
by: Christian Convey | last post by:
Hello, I've got a program that (ideally) perpetually monitors sys.stdin for lines of text. As soon as a line comes in, my program takes some action. The problem is, it seems like a very large amount of data must accumulate on sys.stdin before even my first invocation of readline() returns. This delay prevents my program from being responsive in the way it must be.
8
5782
by: Thierry Lam | last post by:
I can use the python function raw_input() to read any input from the user but how can I add a timeout so that my program exits after x period of time when no input has been entered. Thierry
1
4928
by: Joachim | last post by:
Is there a way to set a timeout for the Console.ReadLine method?
25
5842
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
0
1426
by: Jean-Paul Calderone | last post by:
On Sat, 21 Jun 2008 12:35:02 -0700 (PDT), joamag <joamag@gmail.comwrote: Twisted supports asynchronous handling of stdin on both POSIX and Windows. See stdiodemo.py and stdin.py under the Miscellaenous section at http://twistedmatrix.com/projects/core/documentation/examples/ Jean-Paul
0
8203
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.