Skip to content

Commit 395709b

Browse files
committed
Removed registered Proxy Objects from SharedMemoryManager.
1 parent 594140a commit 395709b

File tree

3 files changed

+25
-94
lines changed

3 files changed

+25
-94
lines changed

Doc/library/multiprocessing.shared_memory.rst

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ same ``numpy.ndarray`` from two distinct Python shells:
205205

206206
This class provides methods for creating and returning :class:`SharedMemory`
207207
instances and for creating a list-like object (:class:`ShareableList`)
208-
backed by shared memory. It also provides methods that create and
209-
return :ref:`multiprocessing-proxy_objects` that support synchronization
210-
across processes (i.e. multi-process-safe locks and semaphores).
208+
backed by shared memory.
211209

212210
Refer to :class:`multiprocessing.managers.BaseManager` for a description
213211
of the inherited *address* and *authkey* optional input arguments and how
@@ -224,38 +222,6 @@ same ``numpy.ndarray`` from two distinct Python shells:
224222
Create and return a new :class:`ShareableList` object, initialized
225223
by the values from the input ``sequence``.
226224

227-
.. method:: Barrier(parties[, action[, timeout]])
228-
229-
Create a shared :class:`threading.Barrier` object and return a
230-
proxy for it.
231-
232-
.. method:: BoundedSemaphore([value])
233-
234-
Create a shared :class:`threading.BoundedSemaphore` object and return
235-
a proxy for it.
236-
237-
.. method:: Condition([lock])
238-
239-
Create a shared :class:`threading.Condition` object and return a proxy
240-
for it. The optional input *lock* supports a proxy for a
241-
:class:`threading.Lock` or :class:`threading.RLock` object.
242-
243-
.. method:: Event()
244-
245-
Create a shared :class:`threading.Event` object and return a proxy for it.
246-
247-
.. method:: Lock()
248-
249-
Create a shared :class:`threading.Lock` object and return a proxy for it.
250-
251-
.. method:: RLock()
252-
253-
Create a shared :class:`threading.RLock` object and return a proxy for it.
254-
255-
.. method:: Semaphore([value])
256-
257-
Create a shared :class:`threading.Semaphore` object and return a proxy
258-
for it.
259225

260226
The following example demonstrates the basic mechanisms of a
261227
:class:`SharedMemoryManager`:

Lib/multiprocessing/shared_memory.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212

1313
from functools import reduce
1414
import mmap
15-
from .managers import dispatch, BaseManager, Server, State, ProcessError, \
16-
BarrierProxy, AcquirerProxy, ConditionProxy, EventProxy
15+
from .managers import dispatch, BaseManager, Server, State, ProcessError
1716
from . import util
1817
import os
1918
import struct
2019
import sys
21-
import threading
2220
import secrets
2321
try:
2422
import _posixshmem
@@ -835,15 +833,3 @@ def ShareableList(self, sequence):
835833
sl.shm.unlink()
836834
raise e
837835
return sl
838-
839-
SharedMemoryManager.register('Barrier', threading.Barrier, BarrierProxy)
840-
SharedMemoryManager.register(
841-
'BoundedSemaphore',
842-
threading.BoundedSemaphore,
843-
AcquirerProxy
844-
)
845-
SharedMemoryManager.register('Condition', threading.Condition, ConditionProxy)
846-
SharedMemoryManager.register('Event', threading.Event, EventProxy)
847-
SharedMemoryManager.register('Lock', threading.Lock, AcquirerProxy)
848-
SharedMemoryManager.register('RLock', threading.RLock, AcquirerProxy)
849-
SharedMemoryManager.register('Semaphore', threading.Semaphore, AcquirerProxy)

Lib/test/_test_multiprocessing.py

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,9 +3751,7 @@ def test_shared_memory_SharedMemoryManager_basics(self):
37513751

37523752
with shared_memory.SharedMemoryManager() as smm2:
37533753
sl = smm2.ShareableList("howdy")
3754-
unnecessary_lock = smm2.Lock()
3755-
with unnecessary_lock:
3756-
shm = smm2.SharedMemory(size=128)
3754+
shm = smm2.SharedMemory(size=128)
37573755
held_name = sl.shm.name
37583756
if sys.platform != "win32":
37593757
with self.assertRaises(FileNotFoundError):
@@ -4944,9 +4942,29 @@ def is_alive(self):
49444942
any(process.is_alive() for process in forked_processes))
49454943

49464944

4947-
class _MixinTestCommonManagerTypes(object):
4945+
class TestSyncManagerTypes(unittest.TestCase):
4946+
"""Test all the types which can be shared between a parent and a
4947+
child process by using a manager which acts as an intermediary
4948+
between them.
4949+
4950+
In the following unit-tests the base type is created in the parent
4951+
process, the @classmethod represents the worker process and the
4952+
shared object is readable and editable between the two.
4953+
4954+
# The child.
4955+
@classmethod
4956+
def _test_list(cls, obj):
4957+
assert obj[0] == 5
4958+
assert obj.append(6)
49484959
4949-
manager_class = None
4960+
# The parent.
4961+
def test_list(self):
4962+
o = self.manager.list()
4963+
o.append(5)
4964+
self.run_worker(self._test_list, o)
4965+
assert o[1] == 6
4966+
"""
4967+
manager_class = multiprocessing.managers.SyncManager
49504968

49514969
def setUp(self):
49524970
self.manager = self.manager_class()
@@ -5056,31 +5074,6 @@ def test_barrier(self):
50565074
o = self.manager.Barrier(5)
50575075
self.run_worker(self._test_barrier, o)
50585076

5059-
5060-
class TestSyncManagerTypes(_MixinTestCommonManagerTypes, unittest.TestCase):
5061-
"""Test all the types which can be shared between a parent and a
5062-
child process by using a manager which acts as an intermediary
5063-
between them.
5064-
5065-
In the following unit-tests the base type is created in the parent
5066-
process, the @classmethod represents the worker process and the
5067-
shared object is readable and editable between the two.
5068-
5069-
# The child.
5070-
@classmethod
5071-
def _test_list(cls, obj):
5072-
assert obj[0] == 5
5073-
assert obj.append(6)
5074-
5075-
# The parent.
5076-
def test_list(self):
5077-
o = self.manager.list()
5078-
o.append(5)
5079-
self.run_worker(self._test_list, o)
5080-
assert o[1] == 6
5081-
"""
5082-
manager_class = multiprocessing.managers.SyncManager
5083-
50845077
@classmethod
50855078
def _test_pool(cls, obj):
50865079
# TODO: fix https://bugs.python.org/issue35919
@@ -5186,20 +5179,6 @@ def test_namespace(self):
51865179
self.run_worker(self._test_namespace, o)
51875180

51885181

5189-
try:
5190-
import multiprocessing.shared_memory
5191-
except ImportError:
5192-
@unittest.skip("SharedMemoryManager not available on this platform")
5193-
class TestSharedMemoryManagerTypes(_MixinTestCommonManagerTypes,
5194-
unittest.TestCase):
5195-
pass
5196-
else:
5197-
class TestSharedMemoryManagerTypes(_MixinTestCommonManagerTypes,
5198-
unittest.TestCase):
5199-
"""Same as above but by using SharedMemoryManager."""
5200-
manager_class = multiprocessing.shared_memory.SharedMemoryManager
5201-
5202-
52035182
class MiscTestCase(unittest.TestCase):
52045183
def test__all__(self):
52055184
# Just make sure names in blacklist are excluded

0 commit comments

Comments
 (0)