From 97d022e7c34cd9368c0631ed8c6e57344e10fee9 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Fri, 3 Jun 2022 02:27:24 -0700 Subject: [PATCH 1/5] Add note warning about entry point guard for asyncio example --- Doc/library/asyncio-eventloop.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 4f0f8c06fee787..81b6a6af78e281 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1208,6 +1208,12 @@ Executing code in thread or process pools asyncio.run(main()) + Note that on macOS, an entry point guard may be needed as the example would + otherwise cause a :exc:`RuntimeError`. See the `Changed in version 3.8 note + `_ + and `Safe importing of main module + `_. + This method returns a :class:`asyncio.Future` object. Use :func:`functools.partial` :ref:`to pass keyword arguments From 16cb2552768b42060cf449dfa96dba5123fa4623 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:07:17 -0700 Subject: [PATCH 2/5] Add entry guard, clarify note on platform --- Doc/library/asyncio-eventloop.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 81b6a6af78e281..a346c6fbdb778c 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1206,12 +1206,12 @@ Executing code in thread or process pools pool, cpu_bound) print('custom process pool', result) - asyncio.run(main()) + if __name__ == '__main__': + asyncio.run(main()) - Note that on macOS, an entry point guard may be needed as the example would - otherwise cause a :exc:`RuntimeError`. See the `Changed in version 3.8 note - `_ - and `Safe importing of main module + Note that on Windows and macOS, the entry point guard may be necessary as the + example would otherwise cause a :exc:`RuntimeError`. For more details, see the + `Safe importing of main module `_. This method returns a :class:`asyncio.Future` object. From 0129bdf0f6429d7983b9e381820faa928c78176c Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Sun, 16 Oct 2022 06:06:48 -0700 Subject: [PATCH 3/5] Add ref target in multiprocessing --- Doc/library/multiprocessing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 2a66b0f65c0882..61c5c6d76c794e 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -2943,6 +2943,8 @@ Global variables However, global variables which are just module level constants cause no problems. +.. _multiprocessing-safe-main-import: + Safe importing of main module Make sure that the main module can be safely imported by a new Python From fd68a5ea4e9c53261c56002f2366a080f1fa7b30 Mon Sep 17 00:00:00 2001 From: Stanley <46876382+slateny@users.noreply.github.com> Date: Sun, 16 Oct 2022 06:07:40 -0700 Subject: [PATCH 4/5] Use rewording for multiprocessing Co-authored-by: C.A.M. Gerlach --- Doc/library/asyncio-eventloop.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index a346c6fbdb778c..cc366607397dd9 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1209,10 +1209,10 @@ Executing code in thread or process pools if __name__ == '__main__': asyncio.run(main()) - Note that on Windows and macOS, the entry point guard may be necessary as the - example would otherwise cause a :exc:`RuntimeError`. For more details, see the - `Safe importing of main module - `_. + Note that the entry point guard (``if __name__ == '__main__'``) + is required for option 3 due to the peculiarities of :mod:`multiprocessing`, + which is used by :class:`~concurrent.futures.ProcessPoolExecutor. + See :ref:`Safe importing of main module `. This method returns a :class:`asyncio.Future` object. From 8ba4b0cb1c11c331c86993149508140287dbd1d3 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Sun, 16 Oct 2022 06:11:05 -0700 Subject: [PATCH 5/5] Add missing grave sign --- Doc/library/asyncio-eventloop.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index cc366607397dd9..a0f19dfb7af5fa 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1211,7 +1211,7 @@ Executing code in thread or process pools Note that the entry point guard (``if __name__ == '__main__'``) is required for option 3 due to the peculiarities of :mod:`multiprocessing`, - which is used by :class:`~concurrent.futures.ProcessPoolExecutor. + which is used by :class:`~concurrent.futures.ProcessPoolExecutor`. See :ref:`Safe importing of main module `. This method returns a :class:`asyncio.Future` object. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy