Skip to content

Commit c4de6b1

Browse files
bskinnCAM-Gerlachterryjreedy
authored
gh-85747: Active voice & suggested edits, 'running/stopping loop' & 'callbacks' subsections of asyncio-eventloop.rst (#100270)
Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 694e346 commit c4de6b1

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Doc/library/asyncio-eventloop.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,24 @@ Running and stopping the loop
186186
.. coroutinemethod:: loop.shutdown_default_executor(timeout=None)
187187

188188
Schedule the closure of the default executor and wait for it to join all of
189-
the threads in the :class:`ThreadPoolExecutor`. After calling this method, a
190-
:exc:`RuntimeError` will be raised if :meth:`loop.run_in_executor` is called
191-
while using the default executor.
189+
the threads in the :class:`~concurrent.futures.ThreadPoolExecutor`.
190+
Once this method has been called,
191+
using the default executor with :meth:`loop.run_in_executor`
192+
will raise a :exc:`RuntimeError`.
192193

193-
The *timeout* parameter specifies the amount of time the executor will
194-
be given to finish joining. The default value is ``None``, which means the
195-
executor will be given an unlimited amount of time.
194+
The *timeout* parameter specifies the amount of time
195+
(in :class:`float` seconds) the executor will be given to finish joining.
196+
With the default, ``None``,
197+
the executor is allowed an unlimited amount of time.
196198

197-
If the timeout duration is reached, a warning is emitted and executor is
198-
terminated without waiting for its threads to finish joining.
199+
If the *timeout* is reached, a :exc:`RuntimeWarning` is emitted
200+
and the default executor is terminated
201+
without waiting for its threads to finish joining.
199202

200-
Note that there is no need to call this function when
201-
:func:`asyncio.run` is used.
203+
.. note::
204+
205+
Do not call this method when using :func:`asyncio.run`,
206+
as the latter handles default executor shutdown automatically.
202207

203208
.. versionadded:: 3.9
204209

@@ -213,22 +218,23 @@ Scheduling callbacks
213218
Schedule the *callback* :term:`callback` to be called with
214219
*args* arguments at the next iteration of the event loop.
215220

221+
Return an instance of :class:`asyncio.Handle`,
222+
which can be used later to cancel the callback.
223+
216224
Callbacks are called in the order in which they are registered.
217225
Each callback will be called exactly once.
218226

219-
An optional keyword-only *context* argument allows specifying a
227+
The optional keyword-only *context* argument specifies a
220228
custom :class:`contextvars.Context` for the *callback* to run in.
221-
The current context is used when no *context* is provided.
222-
223-
An instance of :class:`asyncio.Handle` is returned, which can be
224-
used later to cancel the callback.
229+
Callbacks use the current context when no *context* is provided.
225230

226-
This method is not thread-safe.
231+
Unlike :meth:`call_soon_threadsafe`, this method is not thread-safe.
227232

228233
.. method:: loop.call_soon_threadsafe(callback, *args, context=None)
229234

230-
A thread-safe variant of :meth:`call_soon`. Must be used to
231-
schedule callbacks *from another thread*.
235+
A thread-safe variant of :meth:`call_soon`. When scheduling callbacks from
236+
another thread, this function *must* be used, since :meth:`call_soon` is not
237+
thread-safe.
232238

233239
Raises :exc:`RuntimeError` if called on a loop that's been closed.
234240
This can happen on a secondary thread when the main application is

0 commit comments

Comments
 (0)