bpo-46787: Fix ProcessPoolExecutor exception memory leak (GH-31408) (#31408)

Do not store `ProcessPoolExecutor` work item exception traceback that prevents
exception frame locals from being garbage collected.
This commit is contained in:
themylogin 2022-05-02 22:24:39 +02:00 committed by GitHub
parent c96da83a8e
commit 9c204b148f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -125,6 +125,9 @@ class _ExceptionWithTraceback:
def __init__(self, exc, tb):
tb = ''.join(format_exception(type(exc), exc, 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)

View File

@ -0,0 +1 @@
Fix :class:`concurrent.futures.ProcessPoolExecutor` exception memory leak