[Python-checkins] bpo-46787: Fix `ProcessPoolExecutor exception` memory leak (GH-31408) (GH-31408)

miss-islington webhook-mailer at python.org
Mon May 2 18:51:31 EDT 2022


https://github.com/python/cpython/commit/51b885a38a6cbf1d11d3c49e0d2c6532944fcd4d
commit: 51b885a38a6cbf1d11d3c49e0d2c6532944fcd4d
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-05-02T15:51:20-07:00
summary:

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 9c204b148fad9742ed19b3bce173073cdec79819)

Co-authored-by: themylogin <themylogin at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-02-18-20-09-29.bpo-46787.juwWc0.rst
M Lib/concurrent/futures/process.py

diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index a29e5247ab85c..e574299eb033b 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -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)
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
index 0000000000000..cf167ff48115b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-18-20-09-29.bpo-46787.juwWc0.rst
@@ -0,0 +1 @@
+Fix :class:`concurrent.futures.ProcessPoolExecutor` exception memory leak



More information about the Python-checkins mailing list