Socket object and KeyboardInterrupt exception
PantherSE
pantherse at gmail.com
Mon May 16 17:10:42 EDT 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
More information about the Python-list
mailing list