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: 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: References: From: Devin Jeanpierre 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, Feb 15, 2012 at 8:33 AM, Mel Wilson wrote: > The usual way to do what you're asking is > > if __name__ =3D=3D '__main__': > =C2=A0 =C2=A0main() > =C2=A0 =C2=A0goodbye() > > and write main so that it returns after it's done all the things it's > supposed to do. =C2=A0If you've sprinkled `sys.exit()` all over your code= , then > don't do that. =C2=A0If you're forced to deal with a library that hides > `sys.exit()` calls in the functions, then you have my sympathy. =C2=A0Lib= rary > authors should not do that, and there have been threads on c.l.p explaini= ng > why they shouldn't. In such a case. one can do:: if __name__ =3D=3D '__main__': try: main() except SystemExit: pass goodbye() -- Devin