Re: Coding Style: exiting python programs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2012-09-26 at 22:06 +1000, Amit Saha wrote:
> On Wed, Sep 26, 2012 at 1:04 AM, Will Woods <wwoods@xxxxxxxxxx> wrote:
> > Hey all - here is a quick note about the various ways to exit python
> > programs. Consider this a suggestion for a future CodingStyle / New
> > Developer FAQ, or something.
> >
> >
> > sys.exit(returncode) really just does:
> >     raise SystemExit(returncode)
> > So we can use that rather than importing sys just for sys.exit().
> >
> > Note that SystemExit is a subclass of Exception, so if you're handling
> > Exception anywhere, you're going to catch SystemExit/sys.exit().
> > (This is another reason 'except Exception: ..." is a bad idea.)
> 
> Thanks for the tip. Perhaps you should add that SystemExit is a
> subclass of BaseException and not Exception starting Python 2.5 [1].

Right. This is why we went from a bare 'except' to 'except Exception' in
much of anaconda a couple of years ago -- to not catch SystemExit.

> 
> [1] http://docs.python.org/library/exceptions.html#exceptions.SystemExit
> 
> (Thanks to Nick Coghlan for pointing this to me when i shared your tip
> on twitter).
> 
> Cheers,
> Amit.
> 


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux