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


Groups > comp.lang.python > #20442

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!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*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; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'functions,': 0.18; 'header :In-Reply-To:1': 0.22; 'feb': 0.22; 'code,': 0.28; 'asking': 0.28; 'pass': 0.29; 'subject:skip:a 10': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'solved': 0.30; 'threads': 0.30; 'message- id:@gmail.com': 0.31; 'do.': 0.31; 'thanks': 0.32; 'that,': 0.32; 'supposed': 0.32; 'usual': 0.32; 'there': 0.33; 'header:User- Agent:1': 0.33; 'done': 0.34; 'sense,': 0.34; 'try:': 0.34; 'things': 0.35; 'received:209.85.214': 0.36; 'cc:2**1': 0.36; 'received:10.0.0': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'authors': 0.38; 'should': 0.38; 'that.': 0.39; 'except': 0.39; 'received:209': 0.39; "you've": 0.61; 'your': 0.61; 'perfect': 0.64; '01:52': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=YgkDnx51FV6RlNY8S9mBh42qs9yAQC3VtXqypq5BF58=; b=aEudQMg2WDD1PKAqDJ1hUGP3pSNdSYdykn8iPOJjpGiTYVwg5MsV7Y9Mne2nHlzbNV WpDRDntVnG76BaFXhi8+mfvIJtRzsH5sixvugbUAmuXVV2MCg/cXl/R+g77VI0HRjMIY vTloLL4l3SMBcvrHzVuNq6LaazNWXQ8lltVEI=
Date Wed, 15 Feb 2012 14:35:33 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111224 Thunderbird/9.0.1
MIME-Version 1.0
To Devin Jeanpierre <jeanpierreda@gmail.com>
Subject Re: atexit.register in case of errors
References <mailman.5827.1329311531.27778.python-list@python.org> <jhgc7t$b2m$1@speranza.aioe.org> <CABicbJLYtDwtY+1ihTYhrMnXR2rt5d6K0g-Zu8Ko8_WX1nDF+Q@mail.gmail.com>
In-Reply-To <CABicbJLYtDwtY+1ihTYhrMnXR2rt5d6K0g-Zu8Ko8_WX1nDF+Q@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org, mwilson@the-wire.com
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.5831.1329316538.27778.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329316538 news.xs4all.nl 6903 [2001:888:2000:d::a6]:42559
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20442

Show key headers only | View raw


On 02/15/2012 01:52 PM, Devin Jeanpierre wrote:
> 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

Makes perfect sense, I solved like this then, thanks

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