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


Groups > comp.lang.python > #64827

Re:buggy python interpretter or am I missing something here?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'syntax': 0.04; 'classes,': 0.05; 'elif': 0.05; 'insert': 0.05; 'output': 0.05; 'subject:missing': 0.07; 'clause': 0.09; 'except:': 0.09; 'exception,': 0.09; 'exception.': 0.09; 'executes': 0.09; 'exit': 0.09; 'expected.': 0.09; 'properly.': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'specific.': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'template': 0.14; 'here"': 0.16; 'hierarchy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sys.exit(0)': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'code.': 0.18; 'seems': 0.21; 'print': 0.22; '2.x': 0.24; 'fairly': 0.24; 'script': 0.25; 'class.': 0.26; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'errors': 0.30; "i'm": 0.30; 'code': 0.31; 'option.': 0.31; 'run': 0.32; 'linux': 0.33; 'running': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'subject:?': 0.36; 'expected': 0.38; 'generic': 0.38; 'others.': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'bad': 0.39; 'flow': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'catch': 0.60; 'manually': 0.60; 'break': 0.61; "you're": 0.61; 'bare': 0.84; 'subject:here': 0.84; 'subject::': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:buggy python interpretter or am I missing something here?
Date Mon, 27 Jan 2014 00:36:20 -0500 (EST)
Organization news.gmane.org
References <pan$57cb8$37426877$4ff183f7$e46f1ba0$1@all.net>
X-Gmane-NNTP-Posting-Host dpc6744192012.direcpc.com
X-Newsreader PiaoHong Usenet NewsReaders 1.36
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6020.1390800839.18130.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390800839 news.xs4all.nl 2848 [2001:888:2000:d::a6]:49515
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64827

Show key headers only | View raw


 me <noone@all.net> Wrote in message:
> I'm writing a linux daemon in python 2.x to process batches of GPS/GIS 
> data and I'm running into something that seems to break the expected 
> program flow in a REALLY BAD WAY.
> 
> Consider the attached template script and execute it with the -h option.  
> It is falling through to the except: clause even though try to manually 
> exit with sys.exit(0).  However, if I insert a "raise" into the except 
> clause then the sys.exit(0) executes properly. 
> 
> See the attached code and output from when I run it.
> 
> Not interested in work-arounds.  I want to understand why it doesn't work 
> as expected.
> 

sys.exit() raises an exception,  and you're deliberately eating
 that exception. 

> 
> ------------------------------------------------------------------------------
> 
> def parse_args(a,d):
>     l=len(a)
>     idx=1
>     try:
>         while (idx<l):
>             if (a[idx]=="-#"):
>                 idx=idx+1
>                 d["maxjobs"]=int(a[idx])
>             elif (a[idx]=="-d"):
>                 idx=idx+1
>                 d["basedir"]=a[idx]
>             elif (a[idx]=="-h"):
>                 print "help goes here"
>                 sys.exit(0)
>             elif (a[idx]=="-i"):
>                 idx=idx+1
>                 d["inpipe"]=a[idx]
>             elif (a[idx]=="-o"):
>                 idx=idx+1
>                 d["outpipe"]=a[idx]
>             idx=idx+1
>     except:

Bare except is almost never a good idea. It's going to intercept
 the exit exception, plus control C, syntax errors and others.
 Which you'd have known if you printed the exception code.
 

If you're going to catch an exception,  be specific. Otherwise
 expect the unexpected. 


There is a hierarchy of exception classes,  so you could catch a
 fairly generic class. But you do need to distinguish.
 

-- 
DaveA

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


Thread

buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 03:42 +0000
  buggy python interpretter or am I missing something here? - "TCdaemon.py"  yEnc me <noone@all.net> - 2014-01-27 03:42 +0000
  Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 21:04 -0800
    Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:17 +0000
      Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:03 -0800
        Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:20 +0000
  Re:buggy python interpretter or am I missing something here? Dave Angel <davea@davea.name> - 2014-01-27 00:36 -0500
    Re:buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:02 +0000
      Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:47 -0600
        Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:17 +0000
          Re: buggy python interpretter or am I missing something here? Alister <alister.ware@ntlworld.com> - 2014-01-27 12:19 +0000
          Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 13:48 +0000
          Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 10:23 -0600
            Re: buggy python interpretter or am I missing something here? Dan Sommers <dan@tombstonezero.net> - 2014-01-27 16:38 +0000
          Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:45 +0000
  Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-27 01:21 -0500
    Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:42 +0000
      Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:08 -0800
  Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:46 +0000
    Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:55 -0600
    Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:12 -0800
      Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:30 +0000
        Re: buggy python interpretter or am I missing something here? Peter Otten <__peter__@web.de> - 2014-01-27 09:45 +0100
    Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:17 -0800
      Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:44 +0000
        Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-27 20:01 +1100
          Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 09:32 +0000
            Re: buggy python interpretter or am I missing something here? Neil Cerutti <neilc@norwich.edu> - 2014-01-27 12:56 +0000
            Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 13:56 +0000
            Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 07:33 -0800
              Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 02:53 +1100
                Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 12:22 -0800
                Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 07:29 +1100
                Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 22:25 +0000
                Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-30 18:13 +1300
                Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-30 04:44 -0500
                Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-31 04:06 +0000
                Re: buggy python interpretter or am I missing something here? Kushal Kumaran <kushal.kumaran@gmail.com> - 2014-01-31 10:37 +0530
                Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 19:59 +1300
              Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:22 +0000
            Re: buggy python interpretter or am I missing something here? Michael Torrie <torriem@gmail.com> - 2014-01-27 10:52 -0700

csiph-web