Skip to content

Commit e26c526

Browse files
gh-85299: Add note warning about entry point guard for asyncio example (GH-93457)
(cherry picked from commit 79fd6cc) Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
1 parent 21fbf16 commit e26c526

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
@@ -1232,7 +1232,13 @@ Executing code in thread or process pools
12321232
pool, cpu_bound)
12331233
print('custom process pool', result)
12341234

1235-
asyncio.run(main())
1235+
if __name__ == '__main__':
1236+
asyncio.run(main())
1237+
1238+
Note that the entry point guard (``if __name__ == '__main__'``)
1239+
is required for option 3 due to the peculiarities of :mod:`multiprocessing`,
1240+
which is used by :class:`~concurrent.futures.ProcessPoolExecutor`.
1241+
See :ref:`Safe importing of main module <multiprocessing-safe-main-import>`.
12361242

12371243
This method returns a :class:`asyncio.Future` object.
12381244

Doc/library/multiprocessing.rst

+2
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,8 @@ Global variables
29542954
However, global variables which are just module level constants cause no
29552955
problems.
29562956

2957+
.. _multiprocessing-safe-main-import:
2958+
29572959
Safe importing of main module
29582960

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

0 commit comments

Comments
 (0)