[Python-checkins] [2.7] bpo-34610: Fixed iterator of multiprocessing.managers.DictProxy. (GH-9113). (GH-9500)

Serhiy Storchaka webhook-mailer at python.org
Sat Sep 22 14:34:26 EDT 2018


https://github.com/python/cpython/commit/69d0bc1430d2e9cddf0b39054ddcb86dbbe7927e
commit: 69d0bc1430d2e9cddf0b39054ddcb86dbbe7927e
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-09-22T21:34:16+03:00
summary:

[2.7] bpo-34610: Fixed iterator of multiprocessing.managers.DictProxy. (GH-9113). (GH-9500)

(cherry picked from commit e0e5065daef36dafe10a46eaa8b7800274d73062)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-09-08-12-57-07.bpo-34610.wmoP5j.rst
M Lib/multiprocessing/managers.py
M Lib/test/test_multiprocessing.py

diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index f2cee0c38ce9..118812c8ce7e 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -1059,10 +1059,13 @@ def __imul__(self, value):
 
 
 DictProxy = MakeProxyType('DictProxy', (
-    '__contains__', '__delitem__', '__getitem__', '__len__',
+    '__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
     '__setitem__', 'clear', 'copy', 'get', 'has_key', 'items',
     'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
     ))
+DictProxy._method_to_typeid_ = {
+    '__iter__': 'Iterator',
+    }
 
 
 ArrayProxy = MakeProxyType('ArrayProxy', (
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index 42ccbcdf675d..ff299feed894 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -1135,6 +1135,16 @@ def test_list(self):
         a.append('hello')
         self.assertEqual(f[:], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello']])
 
+    def test_list_iter(self):
+        a = self.list(range(10))
+        it = iter(a)
+        self.assertEqual(list(it), range(10))
+        self.assertEqual(list(it), [])  # exhausted
+        # list modified during iteration
+        it = iter(a)
+        a[0] = 100
+        self.assertEqual(next(it), 100)
+
     def test_dict(self):
         d = self.dict()
         indices = range(65, 70)
@@ -1145,6 +1155,19 @@ def test_dict(self):
         self.assertEqual(sorted(d.values()), [chr(i) for i in indices])
         self.assertEqual(sorted(d.items()), [(i, chr(i)) for i in indices])
 
+    def test_dict_iter(self):
+        d = self.dict()
+        indices = range(65, 70)
+        for i in indices:
+            d[i] = chr(i)
+        it = iter(d)
+        self.assertEqual(list(it), indices)
+        self.assertEqual(list(it), [])  # exhausted
+        # dictionary changed size during iteration
+        it = iter(d)
+        d.clear()
+        self.assertRaises(RuntimeError, next, it)
+
     def test_namespace(self):
         n = self.Namespace()
         n.name = 'Bob'
diff --git a/Misc/NEWS.d/next/Library/2018-09-08-12-57-07.bpo-34610.wmoP5j.rst b/Misc/NEWS.d/next/Library/2018-09-08-12-57-07.bpo-34610.wmoP5j.rst
new file mode 100644
index 000000000000..bffb355ea2ab
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-09-08-12-57-07.bpo-34610.wmoP5j.rst
@@ -0,0 +1 @@
+Fixed iterator of :class:`multiprocessing.managers.DictProxy`.



More information about the Python-checkins mailing list