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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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?