是否可以在ipython中始终运行事件循环,就像它';在jupyter笔记本中完成了什么?
在Jupyter中,始终存在运行事件循环,允许您在后台运行一些协同程序时以交互方式执行代码(例如,使用是否可以在ipython中始终运行事件循环,就像它';在jupyter笔记本中完成了什么?,python,python-3.x,jupyter-notebook,ipython,python-asyncio,Python,Python 3.x,Jupyter Notebook,Ipython,Python Asyncio,在Jupyter中,始终存在运行事件循环,允许您在后台运行一些协同程序时以交互方式执行代码(例如,使用asyncio.create\u task启动)。这样的行为使得测试并发代码更加容易。在ipython中是否可能以某种方式实现相同的行为 我使用的是python 3.8和ipython 7.12。您可以使用。 只需使用pip安装即可: pip3 install aioconsole 然后可以运行apython命令来运行交互式异步python shell,您可以在其中运行异步代码。用法示例: $
asyncio.create\u task
启动)。这样的行为使得测试并发代码更加容易。在ipython中是否可能以某种方式实现相同的行为
我使用的是python 3.8和ipython 7.12。您可以使用。
只需使用pip安装即可:
pip3 install aioconsole
然后可以运行apython
命令来运行交互式异步python shell,您可以在其中运行异步代码。用法示例:
$ apython
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
---
This console is running in an asyncio event loop.
It allows you to wait for coroutines using the '{0}' syntax.
Try: await asyncio.sleep(1, result=3)
---
>>> await asyncio.sleep(1, result=3)
3
>>>
jupyter console可以做到这一点,只需从终端运行
jupyter console
,您就可以开始了。