Skip to content

Commit 8ded472

Browse files
committed
Improve create_queue documentaion with explanation and example (GH-139515)
1 parent 246fe14 commit 8ded472

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Doc/library/concurrent.interpreters.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ managed way.
165165

166166
With this in mind, the :mod:`!concurrent.interpreters` module provides
167167
a :class:`queue.Queue` implementation, available through
168-
:func:`create_queue`.
168+
:func:`create_queue`.
169169

170170
.. _interp-object-sharing:
171171

@@ -228,6 +228,23 @@ This module defines the following functions:
228228

229229
Initialize a new cross-interpreter queue and return a :class:`Queue`
230230
object for it.
231+
Queues created using the function ``create_queue`` can be used to
232+
safely communicate between multiple interpreters. Since the interpreters
233+
are isolated and do not share variables or data directly,
234+
a queue provides a mechanism to exchange data between them.
235+
236+
Example::
237+
238+
from concurrent.interpreters import create_queue
239+
240+
q = create_queue()
241+
242+
# In one interpreter
243+
q.put("Hello")
244+
245+
# In other interpreter
246+
message = q.get()
247+
print(message)
231248

232249

233250
Interpreter objects

0 commit comments

Comments
 (0)