Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-85299: Add note warning about entry point guard for asyncio example (
GH-93457)

(cherry picked from commit 79fd6cc)

Co-authored-by: Stanley <[email protected]>
  • Loading branch information
slateny authored and miss-islington committed Oct 16, 2022
commit 09fe4f9c7eb7721fc75eb30bd97de3cdd3e205e1
8 changes: 7 additions & 1 deletion Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down