Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38142

error in except

From Rodrick Brown <rodrick.brown@gmail.com>
Date 2013-02-04 16:49 -0500
Subject error in except
Newsgroups comp.lang.python
Message-ID <mailman.1335.1360014616.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

For the life of me I cant figure out why this exception is being thrown.
How could I use pdb to debug this?

$ python udp_local2.py server
  File "udp_local2.py", line 36
    except:
         ^
SyntaxError: invalid syntax


#!/usr/bin/env python

import random, socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

MAX = 65535
PORT = 1060

if 2 <= len(sys.argv) <= 3 and sys.argv[1] == 'server':
    interface = sys.argv[2] if len(sys.argv) > 2 else ''
    s.bind((interface, PORT))
    print 'Listening at', s.getsockname()
    while True:
        data, address = s.recvfrom(MAX)
        if random.randint(0, 1):
            print 'The client at', address, 'says:', repr(data)
            s.sendto('Your data was %d bytes' % len(data), address)
        else:
            print 'Pretending to drop packet from', address

elif len(sys.argv) == 3 and sys.argv[1] == 'client':
    hostname = sys.argv[2]
    s.connect((hostname, PORT))
    print 'Client socket name is', s.getsockname()
    delay = 0.1
    while True:
        s.send('This is another message')
        print 'Waiting up to', delay, 'seconds for a reply'
        s.settimeout(delay)
        try:
            data = s.recv(MAX)
        except socket.timeout:
            delay *= 2
            if delay > 2.0:
                raise RuntimeError('I think the server is down')
            except:
                raise
            else:
                break
        print 'The server says', repr(data)
    else:
        print >> sys.stderr, 'usage: %d server [<interfae>]' % sys.argv[0]
        print >> sys.stderr, '   or: %d client <host>' % sys.argv[0]
        sys.exit(2)

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

error in except Rodrick Brown <rodrick.brown@gmail.com> - 2013-02-04 16:49 -0500
  Re: error in except Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 09:21 +1100
    Re: error in except John Evans <john.g.evans.ne@gmail.com> - 2013-02-04 17:37 -0500

csiph-web