]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46787: Fix `ProcessPoolExecutor exception` memory leak (GH-31408) (#31408)
authorthemylogin <themylogin@gmail.com>
Mon, 2 May 2022 20:24:39 +0000 (22:24 +0200)
committerGitHub <noreply@github.com>
Mon, 2 May 2022 20:24:39 +0000 (14:24 -0600)
Do not store `ProcessPoolExecutor` work item exception traceback that prevents
exception frame locals from being garbage collected.

Lib/concurrent/futures/process.py
Misc/NEWS.d/next/Library/2022-02-18-20-09-29.bpo-46787.juwWc0.rst [new file with mode: 0644]

index 695f7733305ed78db765b24e95a21837ffed5701..0d49379c9bf7ce84392fbbbedfb1d292d8f06957 100644 (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)
diff --git a/Misc/NEWS.d/next/Library/2022-02-18-20-09-29.bpo-46787.juwWc0.rst b/Misc/NEWS.d/next/Library/2022-02-18-20-09-29.bpo-46787.juwWc0.rst
new file mode 100644 (file)
index 0000000..cf167ff
--- /dev/null
@@ -0,0 +1 @@
+Fix :class:`concurrent.futures.ProcessPoolExecutor` exception memory leak