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


Groups > comp.lang.python > #20442

Re: atexit.register in case of errors

Date 2012-02-15 14:35 +0000
From Andrea Crotti <andrea.crotti.0@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>
Newsgroups comp.lang.python
Message-ID <mailman.5831.1329316538.27778.python-list@python.org> (permalink)

Show all headers | 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