diff options
author | Stanley <46876382+slateny@users.noreply.github.com> | 2022-10-16 17:04:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 17:04:43 (GMT) |
commit | 79fd6ccdbe00ec95e4d33fc24fe76076282a334e (patch) | |
tree | b0e0356fbfbc3e6cd4277a520f089e7ad21cd972 /Doc/library | |
parent | 35fa5d5e7f2b0971b39b2659dc70cb77e34a7dd6 (diff) | |
download | cpython-79fd6ccdbe00ec95e4d33fc24fe76076282a334e.zip cpython-79fd6ccdbe00ec95e4d33fc24fe76076282a334e.tar.gz cpython-79fd6ccdbe00ec95e4d33fc24fe76076282a334e.tar.bz2 |
gh-85299: Add note warning about entry point guard for asyncio example (#93457)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/asyncio-eventloop.rst | 8 | ||||
-rw-r--r-- | Doc/library/multiprocessing.rst | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 2f306b7..4f12074 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -1253,7 +1253,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. diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index dab115a..5516084 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -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 |