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

(cherry picked from commit 79fd6ccdbe)

Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2022-10-16 10:16:48 -07:00 committed by Pablo Galindo
parent c6df6eecd8
commit a2820a0ec8
No known key found for this signature in database
GPG key ID: FFE87404168BD847
2 changed files with 9 additions and 1 deletions

View file

@ -1206,8 +1206,14 @@ Executing code in thread or process pools
pool, cpu_bound)
print('custom process pool', result)
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.
Use :func:`functools.partial` :ref:`to pass keyword arguments

View file

@ -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