Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Lib/multiprocessing/dummy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class DummyProcess(threading.Thread):

def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None):
threading.Thread.__init__(self, group, target, name, args, kwargs)
self._pid = None
self._children = weakref.WeakKeyDictionary()
Expand Down
4 changes: 2 additions & 2 deletions Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BaseProcess(object):
def _Popen(self):
raise NotImplementedError

def __init__(self, group=None, target=None, name=None, args=(), kwargs={},
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None,
*, daemon=None):
assert group is None, 'group argument must be None for now'
count = next(_process_counter)
Expand All @@ -89,7 +89,7 @@ def __init__(self, group=None, target=None, name=None, args=(), kwargs={},
self._closed = False
self._target = target
self._args = tuple(args)
self._kwargs = dict(kwargs)
self._kwargs = dict(kwargs) if kwargs else {}
self._name = name or type(self).__name__ + '-' + \
':'.join(str(i) for i in self._identity)
if daemon is not None:
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5278,6 +5278,23 @@ def test_invalid_handles(self):
multiprocessing.connection.Connection, -1)


#
# Regression tests for BaseProcess kwargs handling
#

class TestBaseProcessKwargs(unittest.TestCase):
def test_default_kwargs_not_shared_between_instances(self):
# Creating multiple Process instances without passing kwargs
# must create independent empty dicts (no shared state).
p1 = multiprocessing.Process(target=lambda: None)
p2 = multiprocessing.Process(target=lambda: None)
self.assertIsInstance(p1._kwargs, dict)
self.assertIsInstance(p2._kwargs, dict)
self.assertIsNot(p1._kwargs, p2._kwargs)
# Mutating one should not affect the other
p1._kwargs['x'] = 1
self.assertNotIn('x', p2._kwargs)


@hashlib_helper.requires_hashdigest('sha256')
class OtherTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:!`multiprocessing.BaseProcess` defaults ``kwargs`` to ``None`` instead of a shared dictionary.
Loading