timeout using alarm signal question??

I

Ishwar Rattan

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()
---
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top