By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,057 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,057 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.

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)
resp = raw_input('>> ')
if len(resp) > 0: # cancel alaram input is available
else: # try again!
atry = atry + 1

if __name__ == '__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.