Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def start(self):
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):
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ def get_value(self):
# Testcases
#

class DummyCallable(object):
def __call__(self, q, c):
assert isinstance(c, DummyCallable)
q.put(5)


class _TestProcess(BaseTestCase):

ALLOWED_TYPES = ('processes', 'threads')
Expand Down Expand Up @@ -355,6 +361,18 @@ def test_sys_exit(self):
p.join(5)
self.assertEqual(p.exitcode, reason)

def test_lose_target_ref(self):
c = DummyCallable()
wr = weakref.ref(c)
q = self.Queue()
p = self.Process(target=c, args=(q, c))
del c
p.start()
p.join()
self.assertIs(wr(), None)
self.assertEqual(q.get(), 5)


#
#
#
Expand Down