Socket object and KeyboardInterrupt exception

P

PantherSE

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
 

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,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top