@@ -224,11 +224,15 @@ This module defines the following functions:
224224 Initialize a new (idle) Python interpreter
225225 and return a :class: `Interpreter ` object for it.
226226
227- .. function :: create_queue()
227+ .. function :: create_queue(maxsize=0 )
228228
229229 Initialize a new cross-interpreter queue and return a :class: `Queue `
230230 object for it.
231231
232+ *maxsize * is an integer that sets the upperbound limit on the number of
233+ items that can be placed in the queue. Insertion will be blocked once this
234+ size has been reached, until queue items are consumed. If *maxsize * is
235+ less than or equal to zero, the queue size is infinite.
232236
233237Interpreter objects
234238^^^^^^^^^^^^^^^^^^^
@@ -268,7 +272,7 @@ Interpreter objects
268272 Some objects are actually shared and some are copied efficiently,
269273 but most are copied via :mod: `pickle `. See :ref: `interp-object-sharing `.
270274
271- .. method :: exec(code, /, dedent=True )
275+ .. method :: exec(code, /)
272276
273277 Run the given source code in the interpreter (in the current thread).
274278
@@ -319,7 +323,9 @@ Communicating Between Interpreters
319323.. class :: Queue(id)
320324
321325 A wrapper around a low-level, cross-interpreter queue, which
322- implements the :class: `queue.Queue ` interface. The underlying queue
326+ implements all the methods of :class: `queue.Queue ` except for
327+ :meth: `~queue.Queue.task_done `, :meth: `~queue.Queue.join `
328+ and :meth: `~queue.Queue.shutdown `. The underlying queue
323329 can only be created through :func: `create_queue `.
324330
325331 Some objects are actually shared and some are copied efficiently,
@@ -331,17 +337,59 @@ Communicating Between Interpreters
331337
332338 The queue's ID.
333339
340+ .. method :: qsize()
334341
335- .. exception :: QueueEmptyError
342+ Return the number of items in the queue.
343+
344+ .. method :: empty()
345+
346+ Return ``True `` if the queue is empty, ``False `` otherwise.
347+
348+ .. method :: full()
349+
350+ Return ``True `` if the queue is full, ``False `` otherwise.
351+
352+ .. method :: put(obj, block=True, timeout=None)
353+
354+ Put *obj * into the queue. If optional args *block * is true and
355+ *timeout * is ``None `` (the default), block if necessary until a free
356+ slot is available. If *timeout * is a positive number, it blocks at
357+ most *timeout * seconds and raises the :exc: `QueueFull ` exception if
358+ no free slot was available within that time. Otherwise (*block * is
359+ false), put an object on the queue if a free slot is immediately
360+ available, else raise the :exc: `QueueFull ` exception (*timeout * is
361+ ignored in that case).
362+
363+ .. method :: put_nowait(obj)
364+
365+ Equivalent to ``put(obj, block=False) ``.
366+
367+ .. method :: get(block=True, timeout=None)
368+
369+ Remove and return an object from the queue. If optional args *block *
370+ is true and *timeout * is ``None `` (the default), block if necessary
371+ until an object is available. If *timeout * is a positive number, it
372+ blocks at most *timeout * seconds and raises the :exc: `QueueEmpty `
373+ exception if no object was available within that time. Otherwise
374+ (*block * is false), return an object if one is immediately available,
375+ else raise the :exc: `QueueEmpty ` exception (*timeout * is ignored in
376+ that case).
377+
378+ .. method :: get_nowait()
379+
380+ Equivalent to ``get(block=False) ``.
381+
382+
383+ .. exception :: QueueEmpty
336384
337385 This exception, a subclass of :exc: `queue.Empty `, is raised from
338- :meth: `! Queue.get ` and :meth: `! Queue.get_nowait ` when the queue
386+ :meth: `Queue.get ` and :meth: `Queue.get_nowait ` when the queue
339387 is empty.
340388
341- .. exception :: QueueFullError
389+ .. exception :: QueueFull
342390
343391 This exception, a subclass of :exc: `queue.Full `, is raised from
344- :meth: `! Queue.put ` and :meth: `! Queue.put_nowait ` when the queue
392+ :meth: `Queue.put ` and :meth: `Queue.put_nowait ` when the queue
345393 is full.
346394
347395
@@ -382,3 +430,17 @@ Creating an interpreter and running code in it::
382430
383431 t = interp.call_in_thread(run)
384432 t.join()
433+
434+ Communicating between interpreters with a queue::
435+
436+ from concurrent import interpreters
437+
438+ interp = interpreters.create()
439+ queue = interpreters.create_queue()
440+
441+ def worker(queue):
442+ queue.put('spam!')
443+
444+ t = interp.call_in_thread(worker, queue)
445+ print(queue.get())
446+ t.join()
0 commit comments