Alex Rivera | Logout

Does an application-wide exception handler make sense?

Asked 2008-09-18T18:52:30.920
12

Long story short, I have a substantial Python application that, among other things, does outcalls to "losetup", "mount", etc. on Linux. Essentially consuming system resources that must be released when complete.

If my application crashes, I want to ensure these system resources are properly released.

Does it make sense to do something like the following?

def main():
    # TODO: main application entry point
    pass

def cleanup():
    # TODO: release system resources here
    pass

if __name__ == "__main__":
    try:
        main()
    except:
        cleanup()
        raise

Is this something that is typically done? Is there a better way? Perhaps the destructor in a singleton class?

Edit
Report

1 Answer

2

Application wide handler is fine. They are great for logging. Just make sure that the application wide one is durable and is unlikely to crash itself.

answered 2008-09-18T18:54:18.623

Your Answer