Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Socket object and KeyboardInterrupt exception

Reply
Thread Tools

Socket object and KeyboardInterrupt exception

 
 
PantherSE
Guest
Posts: n/a
 
      05-16-2005
Hello,

Ok, here's my situation. I have a small application that listens to
messages on a UDP port.

When I pass None to settimeout(), and I hit Ctrl+C to interrupt the
wait my exception handler catches the KeyboardInterrupt exception.
However, if I pass any value to settimeout() the exception is not
caught.

Here's the code snippet

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 12345)
sock.setblocking(1)
sock.settimeout(100)

try:
data, msgAddr = sock.recvfrom(1024)
except KeyboardInterrupt:
print 'Caught keyboard interrupt, stopping'
except socket.timeout:
print 'Failed to receive message within 100 seconds.'
except Exception:
print 'Caught exception of type Exception'

I'm running python version 2.3.4 on Red Hat Enterprise 3

Thanks in advance for any info

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching a non-Exception object (KeyboardInterrupt) Michael Goerz Python 3 02-04-2008 02:34 PM
Trace KeyboardInterrupt exception? Tony Nelson Python 4 06-15-2006 07:34 PM
Re: exception KeyboardInterrupt and os.system command darren kirby Python 1 11-29-2005 08:26 AM
Re: exception KeyboardInterrupt and os.system command jepler@unpythonic.net Python 3 11-28-2005 06:21 PM
exception KeyboardInterrupt and os.system command darren kirby Python 1 11-27-2005 11:18 PM



Advertisments