Skip to content

Commit 79fd6cc

Browse files
authored
pythongh-85299: Add note warning about entry point guard for asyncio example (python#93457)
1 parent 35fa5d5 commit 79fd6cc

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
@@ -1253,7 +1253,13 @@ Executing code in thread or process pools
12531253
pool, cpu_bound)
12541254
print('custom process pool', result)
12551255

1256-
asyncio.run(main())
1256+
if __name__ == '__main__':
1257+
asyncio.run(main())
1258+
1259+
Note that the entry point guard (``if __name__ == '__main__'``)
1260+
is required for option 3 due to the peculiarities of :mod:`multiprocessing`,
1261+
which is used by :class:`~concurrent.futures.ProcessPoolExecutor`.
1262+
See :ref:`Safe importing of main module <multiprocessing-safe-main-import>`.
12571263

12581264
This method returns a :class:`asyncio.Future` object.
12591265

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)