--- tags: - python --- Use `contextlib.closing` to automatically close something at the end of a block. ``` with closing(blaat) as b: b.do_something(b) ``` is equal to ``` try: b.do_something() finally: b.close() ``` This is used for example with taskflow's [[Persistence]].