Skip to content

Commit 4735ce7

Browse files
committed
gh-156131: add suggested modifications
1 parent edd53ea commit 4735ce7

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

Doc/library/threading.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,28 @@ This module defines the following functions:
223223
.. function:: run(func, /, *args, **kwargs)
224224
run_daemon(func, /, *args, **kwargs)
225225
226-
Run `func(*args, **kwargs)` in a thread and return the corresponding
226+
Run ``func(*args, **kwargs)`` in a thread and return the corresponding
227227
:class:`Thread` object. The thread is started automatically.
228228

229-
With :func:`run_daemon` the thread is set as daemonic.
229+
With :func:`run_daemon`, the thread is set as daemonic.
230230

231-
.. versionadded:: 3.16
231+
Example:
232+
233+
.. code-block:: python
234+
235+
import threading, urllib
236+
237+
def fetch(url, data=None):
238+
response = urllib.request.urlopen(url, data)
239+
# further processing...
240+
241+
t1 = threading.run(fetch, 'https://example.com/')
242+
t2 = threading.run(fetch, 'https://example.com/post', data=payload)
243+
244+
t1.join()
245+
t2.join()
246+
247+
.. versionadded:: next
232248

233249

234250
.. function:: settrace(func)

Doc/whatsnew/3.16.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ symtable
482482
(Contributed by Serhiy Storchaka in :gh:`153844`.)
483483

484484

485+
threading
486+
---------
487+
488+
* Add :func:`threading.run` and :func:`threading.run_daemon`
489+
as a convenient way to start threads.
490+
(Contributed by Romain Vavassori in :gh:`156131`.)
491+
492+
485493
tkinter
486494
-------
487495

0 commit comments

Comments
 (0)