Skip to content

Commit 8a7bff2

Browse files
slatenymiss-islington
authored andcommitted
pythongh-85299: Add note warning about entry point guard for asyncio example (pythonGH-93457)
(cherry picked from commit 79fd6cc) Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
1 parent 928b5f1 commit 8a7bff2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Doc/library/asyncio-eventloop.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,13 @@ Executing code in thread or process pools
11401140
pool, cpu_bound)
11411141
print('custom process pool', result)
11421142

1143-
asyncio.run(main())
1143+
if __name__ == '__main__':
1144+
asyncio.run(main())
1145+
1146+
Note that the entry point guard (``if __name__ == '__main__'``)
1147+
is required for option 3 due to the peculiarities of :mod:`multiprocessing`,
1148+
which is used by :class:`~concurrent.futures.ProcessPoolExecutor`.
1149+
See :ref:`Safe importing of main module <multiprocessing-safe-main-import>`.
11441150

11451151
This method returns a :class:`asyncio.Future` object.
11461152

Doc/library/multiprocessing.rst

+2
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,8 @@ Global variables
29202920
However, global variables which are just module level constants cause no
29212921
problems.
29222922

2923+
.. _multiprocessing-safe-main-import:
2924+
29232925
Safe importing of main module
29242926

29252927
Make sure that the main module can be safely imported by a new Python

0 commit comments

Comments
 (0)