Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38146
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <john.g.evans.ne@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'exception': 0.03; 'syntax': 0.03; '(python': 0.05; 'binary': 0.05; 'debug': 0.05; 'socket': 0.05; 'clause': 0.07; 'except:': 0.07; 'try:': 0.07; 'python': 0.09; 'appropriate.': 0.09; 'prohibits': 0.09; 'unexpected': 0.09; 'cc:addr:python-list': 0.10; 'subject:error': 0.11; '0.2': 0.16; '2.0:': 0.16; 'bracket': 0.16; 'end-of-file': 0.16; 'hex': 0.16; 'indent': 0.16; 'nightmare.': 0.16; 'pdb': 0.16; 'relevant.': 0.16; 'runtimeerror': 0.16; 'syntaxerror:': 0.16; 'tabs': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'fix': 0.17; "shouldn't": 0.17; 'feb': 0.19; 'sort': 0.21; 'error.': 0.21; '(by': 0.22; 'default,': 0.22; 'file:': 0.22; 'cc:2**0': 0.23; '>': 0.23; 'errors': 0.23; "i've": 0.23; 'raise': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'possibly': 0.27; 'dos': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'there.': 0.28; 'this?': 0.28; 'all.': 0.28; 'run': 0.28; '3.1': 0.29; "d'aprano": 0.29; 'spaces': 0.29; 'steven': 0.29; 'url:mailman': 0.29; 'skip:& 10': 0.29; 'source': 0.29; 'this.': 0.29; "skip:' 10": 0.30; 'error': 0.30; 'figure': 0.30; 'seconds': 0.30; 'expect': 0.31; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'comments': 0.33; 'minutes,': 0.33; 'problem': 0.33; 'code:': 0.33; 'likely': 0.33; 'skip:& 20': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'text': 0.34; 'server': 0.35; 'expected': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'characters': 0.36; 'closing': 0.36; 'depends': 0.36; 'level.': 0.36; 'anything': 0.36; 'should': 0.36; 'editor': 0.37; 'does': 0.37; 'level': 0.37; 'being': 0.37; 'why': 0.37; 'rather': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'delete': 0.38; 'instead': 0.39; 'short': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'john': 0.60; 'skip:u 10': 0.60; 'most': 0.61; 'is.': 0.62; 'more': 0.63; 'here': 0.65; 'become': 0.65; 'total': 0.65; 'brown': 0.65; 'else.': 0.65; 'life': 0.66; 'square': 0.75; '0.8': 0.84; '2013': 0.84; 'conclude': 0.84; 'consequently': 0.84; 'try,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=sa7fw1ymLVWCMywqcBEBNDGgSL7EHbjD87TklJ+UcTQ=; b=WM3SAkfgCN/rAYP9Dy0l9hQ6HBtrcTOnH2ugs5D75ubQyE44rCSTuJ7E42uyflnNJP +3JMs+gE76/BTslaSOly5d8+mTM/Dh59rpgGGgHsde3t7mokWFW7VDutWcQ7cmXKMhF3 2NhbqJrYCTICKRNJ4c5mQ79vjvN35eSd4xqqmZqb/DnAkF3m7Ht8WrPC/eWoxj5ifOt1 Qf5WNYqSzO++rUsgmg2ZRcaKvqFwf4A7URDw2nsRQ+fhNxXfUqQtoZPMH0RLmmX7JB0d VU2oYyB8W4Affm3RUYCxSYAUGrqS32dyH5dQ9YZ1x6jipaJKtQYwXyvUngNSxmkYtcpg Jdtg== |
| MIME-Version | 1.0 |
| X-Received | by 10.194.172.197 with SMTP id be5mr38152964wjc.20.1360017430572; Mon, 04 Feb 2013 14:37:10 -0800 (PST) |
| In-Reply-To | <51103461$0$29981$c3e8da3$5496439d@news.astraweb.com> |
| References | <mailman.1335.1360014616.2939.python-list@python.org> <51103461$0$29981$c3e8da3$5496439d@news.astraweb.com> |
| Date | Mon, 4 Feb 2013 17:37:10 -0500 |
| Subject | Re: error in except |
| From | John Evans <john.g.evans.ne@gmail.com> |
| To | "Steven D'Aprano" <steve+comp.lang.python@pearwood.info> |
| Content-Type | multipart/alternative; boundary=089e0122efded66f3e04d4edbbe3 |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1337.1360017438.2939.python-list@python.org> (permalink) |
| Lines | 211 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360017438 news.xs4all.nl 6848 [2001:888:2000:d::a6]:44349 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38146 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Should it not be "try-except-else' instead of 'if-except-else'?
try:
if delay > 2.0:
raise RuntimeError('I think the server is down')
except:
raise
else:
break
On Mon, Feb 4, 2013 at 5:21 PM, Steven D'Aprano <
steve+comp.lang.python@pearwood.info> wrote:
> Rodrick Brown wrote:
>
> > 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
>
> You can't use pdb to debug it, because you can't run the code until you fix
> the syntax error. You use your text editor to debug it.
>
> Sometimes if you have a missing bracket (round, square or curly), Python
> reports the syntax error on the line *after* where it expected the closing
> bracket.
>
> I've also seen unexpected syntax errors if the source code contains binary
> characters such as DOS end-of-file ^Z. Try opening the file in a hex editor
> and looking for anything that shouldn't be there.
>
> But the most likely problem is that you are mixing tabs and spaces, and
> consequently have inadvertently become confused about the indent level. You
> think that the "except" clause is indented level with a try, but it
> actually is indented level with something else. Using spaces for indents is
> good; using tabs for indents is also good; using both at the same time is a
> nightmare. (Python 3 prohibits this.)
>
> I recommend running TabNanny over the file:
>
> python -m tabnanny <file-or-directory>
>
>
> A couple of comments on your code:
>
> > try:
> > data = s.recv(MAX)
> > except socket.timeout:
> > delay *= 2
> > if delay > 2.0:
> > raise RuntimeError('I think the server is down')
>
> Five attempts and a total of 3.1 seconds (0.1 + 0.2 + 0.4 + 0.8 + 1.6) is
> rather short to conclude that a server is down, although it depends on what
> sort of server and where it is. I would have thought 30 seconds is more
> appropriate. (By default, wget doesn't time out for 3 minutes, which is
> possibly overkill.)
>
> But either way, I don't think RuntimeError is the right exception to use. I
> expect that a socket error would be more relevant.
>
> > except:
> > raise
>
> What this does is:
>
> "Unconditionally catch anything. Then raise it again."
>
> Don't do this. The right thing to do here is, just delete it and don't
> catch
> it at all.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
John Evans
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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