Dev HelpersOpen library
← Back

Always perform cleanup

Always perform cleanup. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

events = []
try:
    raise RuntimeError('offline')
except RuntimeError:
    events.append('handled')
finally:
    events.append('cleanup')
print(events)

Sample output

['handled', 'cleanup']