By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

timeout using alarm signal question??

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.