473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

timeout using alarm signal question??

System is Mandrale 9.1 Linux with Pyhton-2.2.3

I want to abort the stdin-read operation if no input is avalable. Is it possible
to achieve this?

Sample code is given below.

-ishwar
---
import sys, signal, time
atry = 0

def now():
return time.ctime(time.time())

def onSignal(signum, stackframe):
global atry
if signum == signal.SIGALRM:
print 'alarm signal seen..', atry

def main():
global atry
while atry < 3:
signal.signal(signal.SIGALRM, onSignal)
signal.alarm(1)
resp = raw_input('>> ')
if len(resp) > 0: # cancel alaram input is available
signal.alarm(0)
break
else: # try again!
atry = atry + 1

if __name__ == '__main__':
main()
---
Jul 18 '05 #1
0 1500

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

Similar topics

3
by: w | last post by:
I'm having problems with this program hanging on the revc(buf). I was trying to figure out a way to allow the socket to timeout. I'm have tried making the socket non-blocking but had on luck. ...
5
by: Jim | last post by:
Hi, I am trying to figure out a way to implement a timeout along with a read() call on an open file. It only has to work on linux, for now I am trying: ret = select.select( ,,, timeout ) if...
0
by: Ishwar Rattan | last post by:
System Mandrake-9.1 Linux with Python-2.2.3 Tyring to time out from a non respnding server using SOCK_STREAM Source is shown below The program quits after first receipt of alram signal with...
0
by: rh0dium | last post by:
Hi all, I don't understand the signal module. I guess I understand what it does in principle but I can't figure out how to use it to timeout an external rsh command after a 5 seconds. Does...
8
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
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
0
by: Carles Pina i Estany | last post by:
Hello, I need to implement timeout for execute method in Mysql queries. I am using MySQLdb. I have tried it: signal.signal(signal.SIGALRM,handler) signal.alarm(1) cursor.execute(sql)...
12
by: Sophie000 | last post by:
I am implementing a peer-to-peer program: When a computer A receives “get file XXX” from stdio, it broadcasts (floods) a request packet to ask others. Both Computer B and C have the file so they...
1
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.