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 8 5773
One way would be to use 'signal' s ... something like this should work
import signal
TIMEOUT = 5 # number of seconds your want for timeout
signal.signal(signal.SIGALRM, input)
signal.alarm(TIMEOUT)
def input():
try:
foo = raw_input()
return foo
except:
# timeout
return
cheers,
amit.
On 11 Jan 2006 13:24:34 -0800, Thierry Lam <la********@gmail.com> wrote: 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
-- http://mail.python.org/mailman/listinfo/python-list
--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
Which Python version are you using? I'm getting the following error
with Python 2.3.4:
Traceback (most recent call last):
File "C:\home\pciroot\vcur\sdk\tools\inter.py", line 32, in ?
signal.signal(signal.SIGALRM, input)
AttributeError: 'module' object has no attribute 'SIGALRM'
Thierry
Is there a windows equivalent for that solution?
its "Python 2.4.1" .. on linux
On 12 Jan 2006 06:34:08 -0800, Thierry Lam <la********@gmail.com> wrote: Is there a windows equivalent for that solution?
-- http://mail.python.org/mailman/listinfo/python-list
--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
Amit Khemka <kh********@gmail.com> writes: import signal TIMEOUT = 5 # number of seconds your want for timeout signal.signal(signal.SIGALRM, input) signal.alarm(TIMEOUT)
def input(): try: foo = raw_input() return foo except: # timeout return
This doesn't work with raw_input under linux, maybe because the
readline lib is snagging the timer interrupt or something. Use
sys.stdin.readline instead. SF bug: http://sourceforge.net/tracker/index...70&atid=105470
I tried it on "Python 2.4.1" on '2.6.11-1.1369_FC4smp with gcc version
4.0.0' .. which works fine .. may be it could be an issue with some
other combinations ..
cheers,
amit
On 12 Jan 2006 07:35:57 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote: Amit Khemka <kh********@gmail.com> writes: import signal TIMEOUT = 5 # number of seconds your want for timeout signal.signal(signal.SIGALRM, input) signal.alarm(TIMEOUT)
def input(): try: foo = raw_input() return foo except: # timeout return
This doesn't work with raw_input under linux, maybe because the readline lib is snagging the timer interrupt or something. Use sys.stdin.readline instead. SF bug:
http://sourceforge.net/tracker/index...70&atid=105470 -- http://mail.python.org/mailman/listinfo/python-list
--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
Another thing that can be tried is:
import threading
a=""
def input():
global a
a = raw_input()
T = threading.Thread(target=input)
T.start()
T.join(2) ## does the trick
...
I have not tested it but i guess should work.
cheers,
amit.
On 1/12/06, Amit Khemka <kh********@gmail.com> wrote: I tried it on "Python 2.4.1" on '2.6.11-1.1369_FC4smp with gcc version 4.0.0' .. which works fine .. may be it could be an issue with some other combinations ..
cheers, amit
On 12 Jan 2006 07:35:57 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: Amit Khemka <kh********@gmail.com> writes: import signal TIMEOUT = 5 # number of seconds your want for timeout signal.signal(signal.SIGALRM, input) signal.alarm(TIMEOUT)
def input(): try: foo = raw_input() return foo except: # timeout return
This doesn't work with raw_input under linux, maybe because the readline lib is snagging the timer interrupt or something. Use sys.stdin.readline instead. SF bug:
http://sourceforge.net/tracker/index...70&atid=105470 -- http://mail.python.org/mailman/listinfo/python-list
-- ---- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest.
--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.
I got the signal to work on linux with sys.stdin.readline() but the
process timeout after x seconds even when I input something. Is there
a way to close the signal after getting a correct input from the
console window?
Thanks
Thierry This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Adrian Casey |
last post by:
I have a python script which uses pexpect and I want to timeout (i.e. raise
pexpect.TIMEOUT) if a long running command does not produce the output I am
expecting. To simulate the 'long running...
|
by: Cath B |
last post by:
I am pretty sure I am getting a command timeout when execute a SQL
procedure that has an output parameter. The code below is in an asp
page that is called using RSGetASPObject. I want to be able...
|
by: glenn |
last post by:
I keep reading all sorts of books on VS that keep telling me to click on
Tools/Visual Studio Command prompt to run this program or that program.
However, I do not have such a menu choice. Where is...
|
by: Jason |
last post by:
Hi all
I get the following error when executing a rather intense stored procedure
from an ASPX page.
I have tried:
- Increasing timeouts on IIS 5.0 (all areas that even mention timeout)
- use...
|
by: Will Gillen |
last post by:
I have an ASP.NET application that is using Windows Integrated
Authentication (IIS) (as opposed to Forms Authentication).
When the user first logs into the application, IIS prompts the user for...
|
by: Mark A. Nadig |
last post by:
I've got a console application in vb.net to replicate the behavior of
the old DOS command CHOICE. I've got a timer event successfully
firing, however the main thread is stuck on the console.read()....
|
by: bonita |
last post by:
If I add the code for user to download the file (e.g.
if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the
following timeout error:
Timeout expired. The timeout period elapsed prior to...
|
by: pb648174 |
last post by:
After executing osql from the command line via the Windows scheduled
task interface, the following error is returned: "Timeout expired"
The code in the sql is as follows:
BACKUP Database...
|
by: SteveBark |
last post by:
Any pointers on this truly appreciated.
I am using net::telnet to connect to a modem pool and then connect with a remote piece of kit. Everything works fine normally, however on occassions the...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |