@@ -170,6 +170,36 @@ With this in mind, the :mod:`!concurrent.interpreters` module provides
170170a :class: `queue.Queue ` implementation, available through
171171:func: `create_queue `.
172172
173+ .. _interp-object-sharing :
174+
175+ "Sharing" Objects
176+ ^^^^^^^^^^^^^^^^^
177+
178+ Any data actually shared between interpreters loses the thread-safety
179+ provided by the :term: `GIL `. There are various options for dealing with
180+ this in extension modules. However, from Python code the lack of
181+ thread-safety means objects can't actually be shared, with a few
182+ exceptions. Instead, a copy must be created, which means mutable
183+ objects won't stay in sync.
184+
185+ By default, most objects are copied with :mod: `pickle ` when they are
186+ passed to another interpreter. Nearly all of the immutable builtin
187+ objects are either directly shared or copied efficiently. For example:
188+
189+ * :const: `None `
190+ * :class: `bool ` (:const: `True ` and :const: `False `)
191+ * :class: `bytes `
192+ * :class: `str `
193+ * :class: `int `
194+ * :class: `float `
195+ * :class: `tuple ` (of similarly supported objects)
196+
197+ There is a small number of Python types that actually share mutable
198+ data between interpreters:
199+
200+ * :class: `memoryview `
201+ * :class: `Queue `
202+
173203
174204Reference
175205---------
@@ -236,6 +266,9 @@ Interpreter objects
236266
237267 Bind objects in the interpreter's :mod: `!__main__ ` module.
238268
269+ Some objects are actually shared and some are copied efficiently,
270+ but most are copied via :mod: `pickle `. See :ref: `interp-object-sharing `.
271+
239272 .. method :: exec(code, /, dedent=True)
240273
241274 Run the given source code in the interpreter (in the current thread).
@@ -290,6 +323,9 @@ Communicating Between Interpreters
290323 implements the :class: `queue.Queue ` interface. The underlying queue
291324 can only be created through :func: `create_queue `.
292325
326+ Some objects are actually shared and some are copied efficiently,
327+ but most are copied via :mod: `pickle `. See :ref: `interp-object-sharing `.
328+
293329 .. attribute :: id
294330
295331 (read-only)
0 commit comments