Skip to content
Open
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
2 changes: 1 addition & 1 deletion Lib/multiprocessing/sharedctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __init__(self, obj, lock=None, ctx=None):
if lock:
self._lock = lock
else:
ctx = ctx or get_context(force=True)
ctx = ctx or get_context()
self._lock = ctx.RLock()
self.acquire = self._lock.acquire
self.release = self._lock.release
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4628,6 +4628,25 @@ def test_sharedctypes(self, lock=False):
def test_synchronize(self):
self.test_sharedctypes(lock=True)

def test_synchronized_wrapper_default_context(self):
# gh-156062: SynchronizedBase used to call get_context() with an
# unexpected argument when neither a lock nor a context was given,
# so the wrapper classes could not be instantiated directly.
from multiprocessing.sharedctypes import (
RawValue, RawArray,
Synchronized, SynchronizedArray, SynchronizedString,
)
for wrapper, obj in [
(Synchronized, RawValue('i', 7)),
(SynchronizedArray, RawArray('d', [1.0, 2.0])),
(SynchronizedString, RawArray('c', 8)),
]:
with self.subTest(wrapper=wrapper.__name__):
wrapped = wrapper(obj)
self.assertIs(wrapped.get_obj(), obj)
with wrapped:
pass

def test_copy(self):
foo = _Foo(2, 5.0, 2 ** 33)
bar = copy(foo)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix :class:`!multiprocessing.sharedctypes.SynchronizedBase` and its subclasses
raising :exc:`TypeError` when instantiated without a *lock* or a *ctx*
argument: they called :func:`multiprocessing.get_context` with an
unsupported ``force`` argument.
Loading