]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-85299: Add note warning about entry point guard for asyncio example (GH-93457)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 16 Oct 2022 17:13:28 +0000 (10:13 -0700)
committerGitHub <noreply@github.com>
Sun, 16 Oct 2022 17:13:28 +0000 (10:13 -0700)
(cherry picked from commit 79fd6ccdbe00ec95e4d33fc24fe76076282a334e)

Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
Doc/library/asyncio-eventloop.rst
Doc/library/multiprocessing.rst

index 343672d350ab088fb9c64ad087ace41e17f603c5..0565f902b7bc8ac51b356782e8d0b2fe25d695c4 100644 (file)
@@ -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.
 
index 95e74b9b93d64df9b4027ec8a663800ca74fb270..f59a61faaa5d2fbddba39a6ceb113a0e1b2b36c4 100644 (file)
@@ -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