Open this example in the interactive library
Source code
from contextlib import ExitStack
with ExitStack() as stack:
stack.callback(print, 'first resource closed')
stack.callback(print, 'second resource closed')
print('working')Sample output
working second resource closed first resource closed
