##// END OF EJS Templates
fix Paul's comments
Matthias Bussonnier -
Show More
@@ -13,7 +13,7 b' ability to run asynchronous code from the REPL. Constructs which are'
13 13 :exc:`SyntaxError` s in the Python REPL can be used seamlessly in IPython.
14 14
15 15 The example given here are for terminal IPython, running async code in a
16 notebook interface or any other frontend using the Jupyter protocol need to
16 notebook interface or any other frontend using the Jupyter protocol needs
17 17 IPykernel version 5.0 or above. The details of how async code runs in
18 18 IPykernel will differ between IPython, IPykernel and their versions.
19 19
@@ -57,8 +57,8 b' Should behave as expected in the IPython REPL::'
57 57
58 58
59 59 You can use the ``c.InteractiveShell.autoawait`` configuration option and set it
60 to :any:`False` to deactivate automatic wrapping of asynchronous code. You can also
61 use the :magic:`%autoawait` magic to toggle the behavior at runtime::
60 to :any:`False` to deactivate automatic wrapping of asynchronous code. You can
61 also use the :magic:`%autoawait` magic to toggle the behavior at runtime::
62 62
63 63 In [1]: %autoawait False
64 64
@@ -110,9 +110,9 b' In the above example, ``async with`` at top level scope is a syntax error in'
110 110 Python.
111 111
112 112 Using this mode can have unexpected consequences if used in interaction with
113 other features of IPython and various registered extensions. In particular if you
114 are a direct or indirect user of the AST transformers, these may not apply to
115 your code.
113 other features of IPython and various registered extensions. In particular if
114 you are a direct or indirect user of the AST transformers, these may not apply
115 to your code.
116 116
117 117 When using command line IPython, the default loop (or runner) does not process
118 118 in the background, so top level asynchronous code must finish for the REPL to
@@ -231,25 +231,26 b' Update ipykernel to version 5.0 or greater::'
231 231 conda install ipykernel ipython --upgrade
232 232
233 233 This should automatically enable ``autoawait`` integration. Unlike terminal
234 IPython all code run on ``asynio`` eventloop, so creating a loop by hand will
235 not work, including with magics like ``%run`` or other framework that create
236 the eventloop themselves. In case like this you can try to use projects like
237 `nest_asyncio <https://github.com/erdewit/nest_asyncio>`_ and see discussion like `this one
234 IPython, all code runs on ``asynio`` eventloop, so creating a loop by hand will
235 not work, including with magics like ``%run`` or other frameworks that create
236 the eventloop themselves. In case like theses you can try to use projects like
237 `nest_asyncio <https://github.com/erdewit/nest_asyncio>`_ and see discussion
238 like `this one
238 239 <https://github.com/jupyter/notebook/issues/3397#issuecomment-419386811>`_
239 240
240 241 Difference between terminal IPython and IPykernel
241 242 =================================================
242 243
243 The exact asynchronous code running behavior can varies between Terminal
244 IPython and IPykernel. The root cause of this behavior is due to IPykernel
245 having a _persistent_ ``asyncio`` loop running, while Terminal IPython start
246 and stop a loop for each code block. This can lead to surprising behavior in
247 some case if you are used to manipulate asyncio loop yourself, see for example
244 The exact asynchronous code running behavior varies between Terminal IPython and
245 IPykernel. The root cause of this behavior is due to IPykernel having a
246 _persistent_ ``asyncio`` loop running, while Terminal IPython starts and stop a
247 loop for each code block. This can lead to surprising behavior in some case if
248 you are used to manipulate asyncio loop yourself, see for example
248 249 :ghissue:`11303` for a longer discussion but here are some of the astonishing
249 250 cases.
250 251
251 This behavior is an implementation detail, and should not be relied upon. It
252 can change without warnings in future versions of IPython.
252 This behavior is an implementation detail, and should not be relied upon. It can
253 change without warnings in future versions of IPython.
253 254
254 255 In terminal IPython a loop is started for each code blocks only if there is top
255 256 level async code::
@@ -283,8 +284,8 b' In a Notebook, with ipykernel the asyncio eventloop is always running::'
283 284 In [3]: loop1 is loop2
284 285 Out[3]: True
285 286
286 In Terminal IPython background task are only processed while the foreground
287 task is running, and IIF the foreground task is async::
287 In Terminal IPython background tasks are only processed while the foreground
288 task is running, if and only if the foreground task is async::
288 289
289 290 $ ipython
290 291 In [1]: import asyncio
@@ -313,4 +314,4 b' task is running, and IIF the foreground task is async::'
313 314 background 6
314 315
315 316 In a Notebook, QtConsole, or any other frontend using IPykernel, background
316 task should behave as expected.
317 tasks should behave as expected.
General Comments 0
You need to be logged in to leave comments. Login now