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


Groups > comp.lang.python > #20438

atexit.register in case of errors

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!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.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'main()': 0.05; '__name__': 0.09; 'def': 0.13; "'__main__':": 0.16; '*always*': 0.16; 'atexit': 0.16; 'main():': 0.16; 'quits': 0.16; 'simplified': 0.16; 'subject:case': 0.16; "doesn't": 0.22; 'code': 0.26; 'function': 0.27; 'import': 0.27; 'exit': 0.29; 'subject:skip:a 10': 0.29; 'problem': 0.29; 'message-id:@gmail.com': 0.31; 'actually': 0.31; "i've": 0.32; 'there': 0.33; 'header:User- Agent:1': 0.33; 'file': 0.34; 'anything': 0.34; 'to:addr:python- list': 0.35; 'received:209.85.214': 0.36; 'created': 0.37; 'received:10.0.0': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'some': 0.38; 'received:209': 0.39; 'application': 0.40; 'to:addr:python.org': 0.40; 'execution.': 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:subject :content-type:content-transfer-encoding; bh=xHT55XYUNWmIvOIK89+TaMqGLgL5kFSHEKQVKpGKUFw=; b=okzahpAvZvcpTaJhEcf0gm/6uNs4NObLfR8xtKKx2wI4ExQqAo69v7S2ss5n8206dU K0Cdpciybg+3YHfGkcn1HGqItAkRBzJq4kPT4k1IKKZmUyOx9KgwVVXDR7ZgPAuiOCFL zk6DaziHPIdJnEiPL4Rn/eV/0BZjFA/2qteTI=
Date Wed, 15 Feb 2012 13:12:06 +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 python-list@python.org
Subject atexit.register in case of errors
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.5827.1329311531.27778.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329311531 news.xs4all.nl 6965 [2001:888:2000:d::a6]:41369
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20438

Show key headers only | View raw


I have the following very simplified situation

from atexit import register


def goodbye():
     print("saying goodbye")


def main():
     while True:
         var = raw_input("read something")


if __name__ == '__main__':
     register(goodbye)
     main()


But in my case the "goodbye" function is deleting the logging file which 
was created
during the application execution.
Now the problem is that it *always* executes, even when the applications 
quits for
some bad errors.

Is there a way to have an exit hook, which doesn't execute in case of 
errors?
I've seen the code of atexit and it apparently doesn't know anything 
about the current
status and why the application is actually quitting, is that correct?

Back to comp.lang.python | Previous | NextNext 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