Skip to content

Commit

Permalink
bpo-46787: Fix ProcessPoolExecutor exception memory leak (GH-31408) (
Browse files Browse the repository at this point in the history
…GH-31408)

Do not store `ProcessPoolExecutor` work item exception traceback that prevents
exception frame locals from being garbage collected.
(cherry picked from commit 9c204b1)

Co-authored-by: themylogin <themylogin@gmail.com>
  • Loading branch information
miss-islington and themylogin committed May 2, 2022
1 parent 3fe4e46 commit 51b885a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/concurrent/futures/process.py
Expand Up @@ -126,6 +126,9 @@ def __init__(self, exc, tb):
tb = traceback.format_exception(type(exc), exc, tb)
tb = ''.join(tb)
self.exc = exc
# Traceback object needs to be garbage-collected as its frames
# contain references to all the objects in the exception scope
self.exc.__traceback__ = None
self.tb = '\n"""\n%s"""' % tb
def __reduce__(self):
return _rebuild_exc, (self.exc, self.tb)
Expand Down
@@ -0,0 +1 @@
Fix :class:`concurrent.futures.ProcessPoolExecutor` exception memory leak

0 comments on commit 51b885a

Please sign in to comment.