]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46787: Fix `ProcessPoolExecutor exception` memory leak (GH-31408) (GH-31408)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 May 2022 22:51:20 +0000 (15:51 -0700)
committerGitHub <noreply@github.com>
Mon, 2 May 2022 22:51:20 +0000 (15:51 -0700)
Do not store `ProcessPoolExecutor` work item exception traceback that prevents
exception frame locals from being garbage collected.
(cherry picked from commit 9c204b148fad9742ed19b3bce173073cdec79819)

Co-authored-by: themylogin <themylogin@gmail.com>
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 a29e5247ab85c6b9f4bcbaa94a342cbda8f4d13e..e574299eb033b659a12a6dce504efbb7a7a0f7e1 100644 (file)
@@ -126,6 +126,9 @@ class _ExceptionWithTraceback:
         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)
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