cleanup in sys.excepthook?

MRAB python at mrabarnett.plus.com
Wed Sep 23 17:54:19 CEST 2009


akonsu wrote:
> hello,
> 
> my script creates files that i need to delete if an exception is
> thrown.
> 
> is this a good pythonic style to do this kind of cleanup in
> sys.excepthook instead of inside except clause of a try block?
> 
Speaking personally, I'd do the cleanup in the except clause if they
needed to be deleted only if there was an exception; I'd use a finally
clause or a 'with' context if they always had to be deleted, whether
there was an exception or not.



More information about the Python-list mailing list