Skip to content

gh-158497: Fix traceback loss and a reference cycle in Executor.map() - #158499

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-executor-map-exceptions
Open

fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-executor-map-exceptions

Conversation

@fedonman

@fedonman fedonman commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

ProcessPoolExecutor.map() returned a failed call's exception without the worker traceback, and _MapResultIterator.__next__() kept the exception it re-raised in a local, which put it in a reference cycle with its own traceback. The chunk worker now wraps the exception in _ExceptionWithTraceback, as _process_worker() does, and __next__() clears the local after raising.

No NEWS entry, since the affected code is new in 3.16 and has not been released.

…r.map()`

_process_chunk() returned a failed call's bare exception, so
ProcessPoolExecutor.map() lost the _RemoteTraceback cause that
_process_worker() attaches. Wrap it in _ExceptionWithTraceback.

_MapResultIterator.__next__() kept the exception it raised in a local,
so the exception referenced its own raising frame through its
traceback. Clear the local after raising, as Future.__get_result()
does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant