[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:13:33 EDT 2022


https://github.com/python/cpython/commit/26307384ffd14d9086ff7aad36ab1fdc408fe6ab
commit: 26307384ffd14d9086ff7aad36ab1fdc408fe6ab
branch: 3.10
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:13:28-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 343672d350ab..0565f902b7bc 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -1140,7 +1140,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 95e74b9b93d6..f59a61faaa5d 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -2920,6 +2920,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