cleanup in sys.excepthook?

A

akonsu

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?

konstantin
 
M

MRAB

akonsu said:
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.
 
J

Jean-Michel Pichavant

akonsu said:
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?

konstantin
def doIt():
pass

try:
doIt()
except Exception, exc:
#cleaning up files



I mean, what is the problem with try except ? It's pythonic. If you tell
us what wrong with it in your case, we may spend time on hacking
sys.excepthook.

Jean-Michel
 
A

akonsu

def doIt():
    pass

try:
    doIt()
except Exception, exc:
    #cleaning up files

I mean, what is the problem with try except ? It's pythonic. If you tell
us what wrong with it in your case, we may spend time on hacking
sys.excepthook.

Jean-Michel

thanks. nothing is wrong with try/except. i just already have an
excepthook handler that uses logger to send emails if a critical error
occurs, so i was just thinking that maybe i can add cleanup there. i
agree, try/except makes more sense.

konstantin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top