@@ -227,11 +227,15 @@ This module defines the following functions:
227227 Initialize a new (idle) Python interpreter
228228 and return a :class: `Interpreter ` object for it.
229229
230- .. function :: create_queue()
230+ .. function :: create_queue(maxsize=0 )
231231
232232 Initialize a new cross-interpreter queue and return a :class: `Queue `
233233 object for it.
234234
235+ *maxsize * is an integer that sets the upperbound limit on the number of
236+ items that can be placed in the queue. Insertion will be blocked once this
237+ size has been reached, until queue items are consumed. If *maxsize * is
238+ less than or equal to zero, the queue size is infinite.
235239
236240Interpreter objects
237241^^^^^^^^^^^^^^^^^^^
@@ -271,7 +275,7 @@ Interpreter objects
271275 Some objects are actually shared and some are copied efficiently,
272276 but most are copied via :mod: `pickle `. See :ref: `interp-object-sharing `.
273277
274- .. method :: exec(code, /, dedent=True )
278+ .. method :: exec(code, /)
275279
276280 Run the given source code in the interpreter (in the current thread).
277281
@@ -322,7 +326,9 @@ Communicating Between Interpreters
322326.. class :: Queue(id)
323327
324328 A wrapper around a low-level, cross-interpreter queue, which
325- implements the :class: `queue.Queue ` interface. The underlying queue
329+ implements all the methods of :class: `queue.Queue ` except for
330+ :meth: `~queue.Queue.task_done `, :meth: `~queue.Queue.join `
331+ and :meth: `~queue.Queue.shutdown `. The underlying queue
326332 can only be created through :func: `create_queue `.
327333
328334 Some objects are actually shared and some are copied efficiently,
@@ -334,17 +340,59 @@ Communicating Between Interpreters
334340
335341 The queue's ID.
336342
343+ .. method :: qsize()
337344
338- .. exception :: QueueEmptyError
345+ Return the number of items in the queue.
346+
347+ .. method :: empty()
348+
349+ Return ``True `` if the queue is empty, ``False `` otherwise.
350+
351+ .. method :: full()
352+
353+ Return ``True `` if the queue is full, ``False `` otherwise.
354+
355+ .. method :: put(obj, block=True, timeout=None)
356+
357+ Put *obj * into the queue. If optional args *block * is true and
358+ *timeout * is ``None `` (the default), block if necessary until a free
359+ slot is available. If *timeout * is a positive number, it blocks at
360+ most *timeout * seconds and raises the :exc: `QueueFull ` exception if
361+ no free slot was available within that time. Otherwise (*block * is
362+ false), put an object on the queue if a free slot is immediately
363+ available, else raise the :exc: `QueueFull ` exception (*timeout * is
364+ ignored in that case).
365+
366+ .. method :: put_nowait(obj)
367+
368+ Equivalent to ``put(obj, block=False) ``.
369+
370+ .. method :: get(block=True, timeout=None)
371+
372+ Remove and return an object from the queue. If optional args *block *
373+ is true and *timeout * is ``None `` (the default), block if necessary
374+ until an object is available. If *timeout * is a positive number, it
375+ blocks at most *timeout * seconds and raises the :exc: `QueueEmpty `
376+ exception if no object was available within that time. Otherwise
377+ (*block * is false), return an object if one is immediately available,
378+ else raise the :exc: `QueueEmpty ` exception (*timeout * is ignored in
379+ that case).
380+
381+ .. method :: get_nowait()
382+
383+ Equivalent to ``get(block=False) ``.
384+
385+
386+ .. exception :: QueueEmpty
339387
340388 This exception, a subclass of :exc: `queue.Empty `, is raised from
341- :meth: `! Queue.get ` and :meth: `! Queue.get_nowait ` when the queue
389+ :meth: `Queue.get ` and :meth: `Queue.get_nowait ` when the queue
342390 is empty.
343391
344- .. exception :: QueueFullError
392+ .. exception :: QueueFull
345393
346394 This exception, a subclass of :exc: `queue.Full `, is raised from
347- :meth: `! Queue.put ` and :meth: `! Queue.put_nowait ` when the queue
395+ :meth: `Queue.put ` and :meth: `Queue.put_nowait ` when the queue
348396 is full.
349397
350398
@@ -385,3 +433,17 @@ Creating an interpreter and running code in it::
385433
386434 t = interp.call_in_thread(run)
387435 t.join()
436+
437+ Communicating between interpreters with a queue::
438+
439+ from concurrent import interpreters
440+
441+ interp = interpreters.create()
442+ queue = interpreters.create_queue()
443+
444+ def worker(queue):
445+ queue.put('spam!')
446+
447+ t = interp.call_in_thread(worker, queue)
448+ print(queue.get())
449+ t.join()
0 commit comments