Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 02:20 AM
PantherSE
Guest
 
Posts: n/a
Default Socket object and KeyboardInterrupt exception

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

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles