From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sun, 16 Oct 2022 17:16:48 +0000 (-0700) Subject: gh-85299: Add note warning about entry point guard for asyncio example (GH-93457) X-Git-Tag: v3.11.0~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2820a0ec87d40c1b49c7295963eedc27f2d1284;p=thirdparty%2FPython%2Fcpython.git 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@users.noreply.github.com> --- diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 555a0f5cb2a7..c1dddbf64aa6 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1206,7 +1206,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 `. This method returns a :class:`asyncio.Future` object. diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index caf24a35fdfc..74e3377b2f59 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -2955,6 +2955,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