Commit bc613153 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-31249: Fix ref cycle in ThreadPoolExecutor (#3178)

* bpo-31249: Fix ref cycle in ThreadPoolExecutor

concurrent.futures: WorkItem.run() used by ThreadPoolExecutor now
breaks a reference cycle between an exception object and the WorkItem
object. ThreadPoolExecutor.shutdown() now also clears its threads
set.

* shutdown() now only clears threads if wait is true.

* Revert changes on shutdown()
parent 5fe59f8e
......@@ -54,8 +54,10 @@ class _WorkItem(object):
try:
result = self.fn(*self.args, **self.kwargs)
except BaseException as e:
self.future.set_exception(e)
except BaseException as exc:
self.future.set_exception(exc)
# Break a reference cycle with the exception 'exc'
self = None
else:
self.future.set_result(result)
......
concurrent.futures: WorkItem.run() used by ThreadPoolExecutor now breaks a
reference cycle between an exception object and the WorkItem object.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment