Skip to content

Commit c467812

Browse files
bpo-46787: Fix ProcessPoolExecutor exception memory leak (GH-31408) (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 <[email protected]>
1 parent f44e629 commit c467812

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Lib/concurrent/futures/process.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def __init__(self, exc, tb):
126126
tb = traceback.format_exception(type(exc), exc, tb)
127127
tb = ''.join(tb)
128128
self.exc = exc
129+
# Traceback object needs to be garbage-collected as its frames
130+
# contain references to all the objects in the exception scope
131+
self.exc.__traceback__ = None
129132
self.tb = '\n"""\n%s"""' % tb
130133
def __reduce__(self):
131134
return _rebuild_exc, (self.exc, self.tb)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :class:`concurrent.futures.ProcessPoolExecutor` exception memory leak

0 commit comments

Comments
 (0)