Skip to content

Commit 07cdaf4

Browse files
authored
DOC Adding IPython section (#165)
1 parent 9d79b11 commit 07cdaf4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/async/async_usage.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,31 @@ Example:
1414

1515
.. literalinclude:: ../code_examples/aiohttp_async.py
1616

17+
IPython
18+
-------
19+
20+
.. Attention::
21+
22+
On some Python environments, like :emphasis:`Jupyter` or :emphasis:`Spyder`,
23+
which are using :emphasis:`IPython`,
24+
an asyncio event loop is already created for you by the environment.
25+
26+
In this case, running the above code might generate the following error::
27+
28+
RuntimeError: asyncio.run() cannot be called from a running event loop
29+
30+
If that happens, depending on the environment,
31+
you should replace :code:`asyncio.run(main())` by either:
32+
33+
.. code-block:: python
34+
35+
await main()
36+
37+
OR:
38+
39+
.. code-block:: python
40+
41+
loop = asyncio.get_running_loop()
42+
loop.create_task(main())
43+
1744
.. _asyncio: https://docs.python.org/3/library/asyncio.html

0 commit comments

Comments
 (0)