Socket object and KeyboardInterrupt exception

Discussion in 'Python' started by PantherSE, May 16, 2005.

  1. PantherSE

    PantherSE Guest

    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
     
    PantherSE, May 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darren kirby
    Replies:
    1
    Views:
    541
    Diez B. Roggisch
    Nov 27, 2005
  2. Replies:
    3
    Views:
    834
    Donn Cave
    Nov 28, 2005
  3. darren kirby
    Replies:
    1
    Views:
    345
  4. Tony Nelson

    Trace KeyboardInterrupt exception?

    Tony Nelson, Jun 13, 2006, in forum: Python
    Replies:
    4
    Views:
    515
    Tony Nelson
    Jun 15, 2006
  5. Michael Goerz
    Replies:
    3
    Views:
    441
    Gabriel Genellina
    Feb 4, 2008
Loading...

Share This Page