I have a long running operation in Python, e.g. shutil.rmtree. Removing a large file system tree can take minutes. I want to ensure that the directory does not end up in a half-deleted state due to the user becoming impatient and interrupting the with CTRL-C.
So far, I have this, but I don't like it, as it feels brittle and weird:
try:
shutil.rmtree(path)
except BaseException:
try:
shutil.rmtree(path)
except Exception
pass
raise
Is there a better way to achieve this?