[2.7] Clear potential ref cycle between Process and Process target (GH-2470) (#2473)
* Clear potential ref cycle between Process and Process target
Besides Process.join() not being called, this was an indirect cause of bpo-30775.
The threading module already does this.
* Add issue reference.
(cherry picked from commit 79d37ae979a65ada0b2ac820279ccc3b1cd41ba6)
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
index f6b03b1..16c4e1e 100644
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -128,6 +128,9 @@
else:
from .forking import Popen
self._popen = Popen(self)
+ # Avoid a refcycle if the target function holds an indirect
+ # reference to the process object (see bpo-30775)
+ del self._target, self._args, self._kwargs
_current_process._children.add(self)
def terminate(self):