Skip to content

Commit 726e57f

Browse files
strictequiv -> syncobj
1 parent a047bc6 commit 726e57f

File tree

2 files changed

+58
-59
lines changed

2 files changed

+58
-59
lines changed

Lib/test/support/interpreters/queues.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class QueueFull(_queues.QueueFull, queue.Full):
3535
_SHARED_ONLY = 0
3636
_PICKLED = 1
3737

38-
def create(maxsize=0, *, strictequiv=False):
38+
def create(maxsize=0, *, syncobj=False):
3939
"""Return a new cross-interpreter queue.
4040
4141
The queue may be used to pass data safely between interpreters.
4242
43-
"strictequiv" sets the default for Queue.put()
43+
"syncobj" sets the default for Queue.put()
4444
and Queue.put_nowait().
4545
"""
46-
fmt = _SHARED_ONLY if strictequiv else _PICKLED
46+
fmt = _SHARED_ONLY if syncobj else _PICKLED
4747
qid = _queues.create(maxsize, fmt)
4848
return Queue(qid, _fmt=fmt)
4949

@@ -115,41 +115,40 @@ def qsize(self):
115115
return _queues.get_count(self._id)
116116

117117
def put(self, obj, timeout=None, *,
118-
strictequiv=None,
118+
syncobj=None,
119119
_delay=10 / 1000, # 10 milliseconds
120120
):
121121
"""Add the object to the queue.
122122
123123
This blocks while the queue is full.
124124
125-
If "strictequiv" is None (the default) then it uses the
125+
If "syncobj" is None (the default) then it uses the
126126
queue's default, set with create_queue()..
127127
128-
If "strictequiv" is false then all objects are supported,
128+
If "syncobj" is false then all objects are supported,
129129
at the expense of worse performance.
130130
131-
If "strictequiv" is true then the corresponding object returned
132-
from Queue.get() will be strictly equivalent to the given obj.
133-
In other words, the two objects will be indistinguishable from
134-
each other, even if the object is mutable. The received object
135-
may actually be the same object, or a copy (immutable values
136-
only), or a proxy.
137-
131+
If "syncobj" is true then the object must be "shareable".
132+
Examples of "shareable" objects include the builtin singletons,
133+
str, and memoryview. One benefit is that such objects are
134+
passed through the queue efficiently.
135+
136+
The key difference, though, is conceptual: the corresponding
137+
object returned from Queue.get() will be strictly equivalent
138+
to the given obj. In other words, the two objects will be
139+
effectively indistinguishable from each other, even if the
140+
object is mutable. The received object may actually be the
141+
same object, or a copy (immutable values only), or a proxy.
138142
Regardless, the received object should be treated as though
139143
the original has been shared directly, whether or not it
140-
actually is. That’s a slightly different and stronger promise
141-
than just equality.
142-
143-
This stricter guarantee requires that the provided object
144-
must be "shareable". Examples of "shareable" types include
145-
the builtin singletons, str, and memoryview. An additional
146-
benefit is that such objects will be passed through the queue
147-
efficiently.
144+
actually is. That's a slightly different and stronger promise
145+
than just (initial) equality, which is all "syncobj=False"
146+
can promise.
148147
"""
149-
if strictequiv is None:
148+
if syncobj is None:
150149
fmt = self._fmt
151150
else:
152-
fmt = _SHARED_ONLY if strictequiv else _PICKLED
151+
fmt = _SHARED_ONLY if syncobj else _PICKLED
153152
if timeout is not None:
154153
timeout = int(timeout)
155154
if timeout < 0:
@@ -168,11 +167,11 @@ def put(self, obj, timeout=None, *,
168167
else:
169168
break
170169

171-
def put_nowait(self, obj, *, strictequiv=None):
172-
if strictequiv is None:
170+
def put_nowait(self, obj, *, syncobj=None):
171+
if syncobj is None:
173172
fmt = self._fmt
174173
else:
175-
fmt = _SHARED_ONLY if strictequiv else _PICKLED
174+
fmt = _SHARED_ONLY if syncobj else _PICKLED
176175
if fmt is _PICKLED:
177176
obj = pickle.dumps(obj)
178177
try:

Lib/test/test_interpreters/test_queues.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def test_shareable(self):
5858

5959
with self.subTest('same interpreter'):
6060
queue2 = queues.create()
61-
queue1.put(queue2, strictequiv=True)
61+
queue1.put(queue2, syncobj=True)
6262
queue3 = queue1.get()
6363
self.assertIs(queue3, queue2)
6464

6565
with self.subTest('from current interpreter'):
6666
queue4 = queues.create()
67-
queue1.put(queue4, strictequiv=True)
67+
queue1.put(queue4, syncobj=True)
6868
out = _run_output(interp, dedent("""
6969
queue4 = queue1.get()
7070
print(queue4.id)
@@ -75,7 +75,7 @@ def test_shareable(self):
7575
with self.subTest('from subinterpreter'):
7676
out = _run_output(interp, dedent("""
7777
queue5 = queues.create()
78-
queue1.put(queue5, strictequiv=True)
78+
queue1.put(queue5, syncobj=True)
7979
print(queue5.id)
8080
"""))
8181
qid = int(out)
@@ -118,7 +118,7 @@ class TestQueueOps(TestBase):
118118
def test_empty(self):
119119
queue = queues.create()
120120
before = queue.empty()
121-
queue.put(None, strictequiv=True)
121+
queue.put(None, syncobj=True)
122122
during = queue.empty()
123123
queue.get()
124124
after = queue.empty()
@@ -133,7 +133,7 @@ def test_full(self):
133133
queue = queues.create(3)
134134
for _ in range(3):
135135
actual.append(queue.full())
136-
queue.put(None, strictequiv=True)
136+
queue.put(None, syncobj=True)
137137
actual.append(queue.full())
138138
for _ in range(3):
139139
queue.get()
@@ -147,16 +147,16 @@ def test_qsize(self):
147147
queue = queues.create()
148148
for _ in range(3):
149149
actual.append(queue.qsize())
150-
queue.put(None, strictequiv=True)
150+
queue.put(None, syncobj=True)
151151
actual.append(queue.qsize())
152152
queue.get()
153153
actual.append(queue.qsize())
154-
queue.put(None, strictequiv=True)
154+
queue.put(None, syncobj=True)
155155
actual.append(queue.qsize())
156156
for _ in range(3):
157157
queue.get()
158158
actual.append(queue.qsize())
159-
queue.put(None, strictequiv=True)
159+
queue.put(None, syncobj=True)
160160
actual.append(queue.qsize())
161161
queue.get()
162162
actual.append(queue.qsize())
@@ -165,9 +165,9 @@ def test_qsize(self):
165165

166166
def test_put_get_main(self):
167167
expected = list(range(20))
168-
for strictequiv in (True, False):
169-
kwds = dict(strictequiv=strictequiv)
170-
with self.subTest(f'strictequiv={strictequiv}'):
168+
for syncobj in (True, False):
169+
kwds = dict(syncobj=syncobj)
170+
with self.subTest(f'syncobj={syncobj}'):
171171
queue = queues.create()
172172
for i in range(20):
173173
queue.put(i, **kwds)
@@ -176,9 +176,9 @@ def test_put_get_main(self):
176176
self.assertEqual(actual, expected)
177177

178178
def test_put_timeout(self):
179-
for strictequiv in (True, False):
180-
kwds = dict(strictequiv=strictequiv)
181-
with self.subTest(f'strictequiv={strictequiv}'):
179+
for syncobj in (True, False):
180+
kwds = dict(syncobj=syncobj)
181+
with self.subTest(f'syncobj={syncobj}'):
182182
queue = queues.create(2)
183183
queue.put(None, **kwds)
184184
queue.put(None, **kwds)
@@ -188,9 +188,9 @@ def test_put_timeout(self):
188188
queue.put(None, **kwds)
189189

190190
def test_put_nowait(self):
191-
for strictequiv in (True, False):
192-
kwds = dict(strictequiv=strictequiv)
193-
with self.subTest(f'strictequiv={strictequiv}'):
191+
for syncobj in (True, False):
192+
kwds = dict(syncobj=syncobj)
193+
with self.subTest(f'syncobj={syncobj}'):
194194
queue = queues.create(2)
195195
queue.put_nowait(None, **kwds)
196196
queue.put_nowait(None, **kwds)
@@ -199,7 +199,7 @@ def test_put_nowait(self):
199199
queue.get()
200200
queue.put_nowait(None, **kwds)
201201

202-
def test_put_strictequiv(self):
202+
def test_put_syncobj(self):
203203
for obj in [
204204
None,
205205
True,
@@ -210,7 +210,7 @@ def test_put_strictequiv(self):
210210
]:
211211
with self.subTest(repr(obj)):
212212
queue = queues.create()
213-
queue.put(obj, strictequiv=True)
213+
queue.put(obj, syncobj=True)
214214
obj2 = queue.get()
215215
self.assertEqual(obj2, obj)
216216

@@ -221,9 +221,9 @@ def test_put_strictequiv(self):
221221
with self.subTest(repr(obj)):
222222
queue = queues.create()
223223
with self.assertRaises(interpreters.NotShareableError):
224-
queue.put(obj, strictequiv=True)
224+
queue.put(obj, syncobj=True)
225225

226-
def test_put_not_strictequiv(self):
226+
def test_put_not_syncobj(self):
227227
for obj in [
228228
None,
229229
True,
@@ -237,7 +237,7 @@ def test_put_not_strictequiv(self):
237237
]:
238238
with self.subTest(repr(obj)):
239239
queue = queues.create()
240-
queue.put(obj, strictequiv=False)
240+
queue.put(obj, syncobj=False)
241241
obj2 = queue.get()
242242
self.assertEqual(obj2, obj)
243243

@@ -251,9 +251,9 @@ def test_get_nowait(self):
251251
with self.assertRaises(queues.QueueEmpty):
252252
queue.get_nowait()
253253

254-
def test_put_get_default_strictequiv(self):
254+
def test_put_get_default_syncobj(self):
255255
expected = list(range(20))
256-
queue = queues.create(strictequiv=True)
256+
queue = queues.create(syncobj=True)
257257
for i in range(20):
258258
queue.put(i)
259259
actual = [queue.get() for _ in range(20)]
@@ -264,9 +264,9 @@ def test_put_get_default_strictequiv(self):
264264
with self.assertRaises(interpreters.NotShareableError):
265265
queue.put(obj)
266266

267-
def test_put_get_default_not_strictequiv(self):
267+
def test_put_get_default_not_syncobj(self):
268268
expected = list(range(20))
269-
queue = queues.create(strictequiv=False)
269+
queue = queues.create(syncobj=False)
270270
for i in range(20):
271271
queue.put(i)
272272
actual = [queue.get() for _ in range(20)]
@@ -285,7 +285,7 @@ def test_put_get_same_interpreter(self):
285285
from test.support.interpreters import queues
286286
queue = queues.create()
287287
orig = b'spam'
288-
queue.put(orig, strictequiv=True)
288+
queue.put(orig, syncobj=True)
289289
obj = queue.get()
290290
assert obj == orig, 'expected: obj == orig'
291291
assert obj is not orig, 'expected: obj is not orig'
@@ -298,7 +298,7 @@ def test_put_get_different_interpreters(self):
298298
self.assertEqual(len(queues.list_all()), 2)
299299

300300
obj1 = b'spam'
301-
queue1.put(obj1, strictequiv=True)
301+
queue1.put(obj1, syncobj=True)
302302

303303
out = _run_output(
304304
interp,
@@ -315,7 +315,7 @@ def test_put_get_different_interpreters(self):
315315
obj2 = b'eggs'
316316
print(id(obj2))
317317
assert queue2.qsize() == 0, 'expected: queue2.qsize() == 0'
318-
queue2.put(obj2, strictequiv=True)
318+
queue2.put(obj2, syncobj=True)
319319
assert queue2.qsize() == 1, 'expected: queue2.qsize() == 1'
320320
"""))
321321
self.assertEqual(len(queues.list_all()), 2)
@@ -337,8 +337,8 @@ def test_put_cleared_with_subinterpreter(self):
337337
queue = queues.Queue({queue.id})
338338
obj1 = b'spam'
339339
obj2 = b'eggs'
340-
queue.put(obj1, strictequiv=True)
341-
queue.put(obj2, strictequiv=True)
340+
queue.put(obj1, syncobj=True)
341+
queue.put(obj2, syncobj=True)
342342
"""))
343343
self.assertEqual(queue.qsize(), 2)
344344

@@ -360,12 +360,12 @@ def f():
360360
break
361361
except queues.QueueEmpty:
362362
continue
363-
queue2.put(obj, strictequiv=True)
363+
queue2.put(obj, syncobj=True)
364364
t = threading.Thread(target=f)
365365
t.start()
366366

367367
orig = b'spam'
368-
queue1.put(orig, strictequiv=True)
368+
queue1.put(orig, syncobj=True)
369369
obj = queue2.get()
370370
t.join()
371371

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy