[Python-checkins] gh-85299: Add note warning about entry point guard for asyncio example (GH-93457)

miss-islington webhook-mailer at python.org
Sun Oct 16 13:16:53 EDT 2022


https://github.com/python/cpython/commit/e26c526fd4f483fdaa821850392149d40d41d9ea
commit: e26c526fd4f483fdaa821850392149d40d41d9ea
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-10-16T10:16:48-07:00
summary:

gh-85299: Add note warning about entry point guard for asyncio example (GH-93457)

(cherry picked from commit 79fd6ccdbe00ec95e4d33fc24fe76076282a334e)

Co-authored-by: Stanley <46876382+slateny at users.noreply.github.com>

files:
M Doc/library/asyncio-eventloop.rst
M Doc/library/multiprocessing.rst

diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
index 8125612de58a..93bca96fff6f 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -1232,7 +1232,13 @@ 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 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 <multiprocessing-safe-main-import>`.
 
    This method returns a :class:`asyncio.Future` object.
 
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index dab115acdc20..551608478067 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -2954,6 +2954,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



More information about the Python-checkins mailing list