Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Add note warning about entry point guard for asyncio example
  • Loading branch information
slateny committed Jun 3, 2022
commit 97d022e7c34cd9368c0631ed8c6e57344e10fee9
6 changes: 6 additions & 0 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,12 @@ Executing code in thread or process pools

asyncio.run(main())

Note that on macOS, an entry point guard may be needed as the example would
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to just add __name__ == '__main__'. This happens on Windows too not just macOS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, Windows also defaults to spawn so looks like it runs into the same issue as mac. Should this note still remain as an fyi, or just change the example to fix the problem and leave out the note? It's customary to have the guard in general but knowing why it fails without might still be helpful, but I don't feel too strongly either way.

otherwise cause a :exc:`RuntimeError`. See the `Changed in version 3.8 note
<https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods>`_
and `Safe importing of main module
<https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods>`_.

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

Use :func:`functools.partial` :ref:`to pass keyword arguments
Expand Down