Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8370496

Browse files
committed
asyncio: add a note about (non) thread safety in each class
1 parent 532c69a commit 8370496

6 files changed

Lines changed: 22 additions & 0 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ It provides multiple facilities, amongst which:
2222

2323
Base class of event loops.
2424

25+
This class is :ref:`not thread safe <asyncio-multithreading>`.
26+
2527
Run an event loop
2628
-----------------
2729

@@ -104,6 +106,9 @@ keywords to your callback, use :func:`functools.partial`. For example,
104106

105107
Like :meth:`call_soon`, but thread safe.
106108

109+
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
110+
section of the documentation.
111+
107112

108113
.. _asyncio-delayed-calls:
109114

Doc/library/asyncio-protocol.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ then call the transport's methods for various purposes.
2323
subprocess pipes. The methods available on a transport depend on
2424
the transport's kind.
2525

26+
The transport classes are :ref:`not thread safe <asyncio-multithreading>`.
27+
2628

2729
BaseTransport
2830
-------------

Doc/library/asyncio-queue.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Queue
3131
be interrupted between calling :meth:`qsize` and doing an operation on the
3232
Queue.
3333

34+
This class is :ref:`not thread safe <asyncio-multithreading>`.
35+
3436
.. versionchanged:: 3.4.3
3537
New :meth:`join` and :meth:`task_done` methods.
3638

Doc/library/asyncio-stream.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ StreamReader
8585

8686
.. class:: StreamReader(limit=None, loop=None)
8787

88+
This class is :ref:`not thread safe <asyncio-multithreading>`.
89+
8890
.. method:: exception()
8991

9092
Get the exception.
@@ -155,6 +157,8 @@ StreamWriter
155157
wait for flow control. It also adds a transport attribute which references
156158
the :class:`Transport` directly.
157159

160+
This class is :ref:`not thread safe <asyncio-multithreading>`.
161+
158162
.. attribute:: transport
159163

160164
Transport.

Doc/library/asyncio-subprocess.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ Process
193193
:meth:`~subprocess.Popen.wait` method of the :class:`~subprocess.Popen`
194194
class is implemented as a busy loop.
195195

196+
This class is :ref:`not thread safe <asyncio-multithreading>`. See also the
197+
:ref:`Subprocess and threads <asyncio-subprocess-threads>` section.
198+
196199
.. coroutinemethod:: wait()
197200

198201
Wait for child process to terminate. Set and return :attr:`returncode`
@@ -310,6 +313,8 @@ are limits:
310313
subprocesses from other threads. Call the :func:`get_child_watcher`
311314
function in the main thread to instantiate the child watcher.
312315

316+
The :class:`asyncio.subprocess.Process` class is not thread safe.
317+
313318
.. seealso::
314319

315320
The :ref:`Concurrency and multithreading in asyncio

Doc/library/asyncio-task.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ Future
209209
:func:`~concurrent.futures.as_completed` functions in the
210210
:mod:`concurrent.futures` package.
211211

212+
This class is :ref:`not thread safe <asyncio-multithreading>`.
213+
212214
.. method:: cancel()
213215

214216
Cancel the future and schedule callbacks.
@@ -375,6 +377,8 @@ Task
375377
Don't directly create :class:`Task` instances: use the :func:`async`
376378
function or the :meth:`BaseEventLoop.create_task` method.
377379

380+
This class is :ref:`not thread safe <asyncio-multithreading>`.
381+
378382
.. classmethod:: all_tasks(loop=None)
379383

380384
Return a set of all tasks for an event loop.

0 commit comments

Comments
 (0)