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


Groups > comp.lang.python > #20441

Re: atexit.register in case of errors

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'main()': 0.05; '__name__': 0.09; 'am,': 0.12; 'library': 0.13; 'case.': 0.15; "'__main__':": 0.16; 'hides': 0.16; 'subject:case': 0.16; '\xc2\xa0if': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'functions,': 0.18; 'cc:no real name:2**0': 0.21; 'header:In- Reply-To:1': 0.22; 'feb': 0.22; 'cc:2**0': 0.26; 'code,': 0.28; 'asking': 0.28; 'pass': 0.29; 'message-id:@mail.gmail.com': 0.29; 'subject:skip:a 10': 0.29; 'cc:addr:python.org': 0.29; 'threads': 0.30; 'do.': 0.31; 'that,': 0.32; 'supposed': 0.32; 'usual': 0.32; 'there': 0.33; 'done': 0.34; 'try:': 0.34; 'things': 0.35; 'received:209.85.160': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.38; 'authors': 0.38; 'should': 0.38; 'received:209.85.160.46': 0.39; 'received:mail- pw0-f46.google.com': 0.39; 'that.': 0.39; 'except': 0.39; 'received:209': 0.39; "you've": 0.61; 'your': 0.61
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=T8l5rw1HGjTTVLRB9wbvOm0QFn3fNdJVDo6Fp2cDLFY=; b=Pfc7Yfrp/jHlWJwZg5VZ4bnzoh+iI9ew9W8aLZ5JJJZtL+oPBKyig2bgpjv+grw+tm LgnYiDL+qgbCzop+VrtIWSQmG75lEMnTMf0pSKEoiN6lQ8OkVoI/uVjjgC+P0dYnZIVw Kwp9Xid8cQ2AWB4MJrZ5lwoHhKZ3CIGSap+dY=
MIME-Version 1.0
In-Reply-To <jhgc7t$b2m$1@speranza.aioe.org>
References <mailman.5827.1329311531.27778.python-list@python.org> <jhgc7t$b2m$1@speranza.aioe.org>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Wed, 15 Feb 2012 08:52:21 -0500
Subject Re: atexit.register in case of errors
To mwilson@the-wire.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.5829.1329313984.27778.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329313984 news.xs4all.nl 6879 [2001:888:2000:d::a6]:60558
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20441

Show key headers only | View raw


On Wed, Feb 15, 2012 at 8:33 AM, Mel Wilson <mwilson@the-wire.com> wrote:
> The usual way to do what you're asking is
>
> if __name__ == '__main__':
>    main()
>    goodbye()
>
> and write main so that it returns after it's done all the things it's
> supposed to do.  If you've sprinkled `sys.exit()` all over your code, then
> don't do that.  If you're forced to deal with a library that hides
> `sys.exit()` calls in the functions, then you have my sympathy.  Library
> authors should not do that, and there have been threads on c.l.p explaining
> why they shouldn't.

In such a case. one can do::

    if __name__ == '__main__':
        try:
            main()
        except SystemExit:
            pass
        goodbye()

-- Devin

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


Thread

atexit.register in case of errors Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-15 13:12 +0000
  Re: atexit.register in case of errors Mel Wilson <mwilson@the-wire.com> - 2012-02-15 08:33 -0500
    Re: atexit.register in case of errors Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-15 08:52 -0500
      Re: atexit.register in case of errors Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-02-15 16:18 +0100
        Re: atexit.register in case of errors Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-15 15:41 +0000
    Re: atexit.register in case of errors Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-15 14:35 +0000
  Re: atexit.register in case of errors Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-15 10:40 -0800
  Re: atexit.register in case of errors Miki Tebeka <miki.tebeka@gmail.com> - 2012-02-15 10:40 -0800

csiph-web