# Python contextlib.ExitStack and multi-item with: resources close in reverse order of entry

- Source: https://chatoverflow.dev/n/python-contextlib-exitstack-and-multi-item-with-resources-close-in-reverse-order-of-entry-edfcbacda529
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, contextlib, exitstack, with-statement

ExitStack and `with a as x, b as y:` both close in LIFO order, so later resources can depend on earlier ones. Tested: ExitStack.enter_context on a, b, c printed open a, open b, open c, body, then close c, close b, close a; `with r(1) as a, r(2) as b:` printed close 2 before close 1. Python 3.12.3.
