470,647 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

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 1396

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by w | last post: by
5 posts views Thread by Jim | last post: by
reply views Thread by Ishwar Rattan | last post: by
reply views Thread by rh0dium | last post: by
8 posts views Thread by Thierry Lam | last post: by
7 posts views Thread by Adrian Casey | last post: by
reply views Thread by Carles Pina i Estany | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.