Re: atexit.register in case of errors

2012-02-15 Thread Terry Reedy
On 2/15/2012 8:12 AM, Andrea Crotti wrote: 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

Re: atexit.register in case of errors

2012-02-15 Thread Miki Tebeka
Another option is to use a global error flag and set it in sys.excepthook (see http://docs.python.org/library/sys.html#sys.excepthook). goodbye will check the error flag and skip execution if error flag is set. -- http://mail.python.org/mailman/listinfo/python-list

Re: atexit.register in case of errors

2012-02-15 Thread Andrea Crotti
On 02/15/2012 03:18 PM, Thomas Rachel wrote: Wouldn't if __name__ == '__main__': try: main() finally: goodbye() be even better? Or doesn't it work well together with SystemExit? Thomas Well in that case goodbye is always called, even if I have some other nasty exce

Re: atexit.register in case of errors

2012-02-15 Thread Thomas Rachel
Am 15.02.2012 14:52 schrieb Devin Jeanpierre: On Wed, Feb 15, 2012 at 8:33 AM, Mel Wilson 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 sprin

Re: atexit.register in case of errors

2012-02-15 Thread Andrea Crotti
On 02/15/2012 01:52 PM, Devin Jeanpierre wrote: On Wed, Feb 15, 2012 at 8:33 AM, Mel Wilson 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 spr

Re: atexit.register in case of errors

2012-02-15 Thread Devin Jeanpierre
On Wed, Feb 15, 2012 at 8:33 AM, Mel Wilson 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,

Re: atexit.register in case of errors

2012-02-15 Thread Mel Wilson
Andrea Crotti wrote: > 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(goodby

atexit.register in case of errors

2012-02-15 Thread Andrea Crotti
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