File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,10 @@ def _get_exithandlers():
220220 return exithandlers
221221 # callbacks is a list of tuples: [(func, args, kwargs), ...]
222222 # Normalize kwargs to ensure it's always a dict (not None)
223- for item in callbacks_list:
223+ # Note: In Python 3.14+, atexit stores callbacks in LIFO order
224+ # (most recently registered first), but we return them in FIFO
225+ # order (registration order) for consistency with earlier versions
226+ for item in reversed (callbacks_list):
224227 func, args, kwargs = item
225228 if kwargs is None :
226229 kwargs = {}
@@ -251,6 +254,9 @@ def _set_exithandlers(exithandlers):
251254
252255 # We could do this more efficiently by directly rebuilding the array
253256 # of atexit_callbacks, but this is much simpler
257+ # Note: exithandlers is in registration order (FIFO).
258+ # In Python 3.14+, atexit.register prepends to the list (LIFO),
259+ # so registering in forward order gives us the correct execution order.
254260 for callback in exithandlers:
255261 atexit.register(callback[0 ], * callback[1 ], ** callback[2 ])
256262
You can’t perform that action at this time.
0 commit comments