Removing `@register_integration("asyncio")` and `def loop_asyncio(kernel):`
还没有人认领这个 Issue。
评估
调研方向
从链接的集成代码附近的 ipykernel/eventloops.py 开始,跟踪它如何从 kernelbase.py 中的 enter_eventloop() 调用。将其行为与 pull request 1469 中描述的 asyncio 事件循环更改进行比较,然后验证重复执行 %gui asyncio 不再导致 asyncio 任务数量增长或浪费 CPU。
由索引模型根据 Issue 内容生成。
描述
In current versions of ipykernel, when you execute in jupyter, vscode jupyter,
%gui asyncio
then after a while, when you execute
import asyncio
asyncio.all_tasks()```
you will get and see like
{<Task pending name='Task-52016' coro=<_async_in_context.<locals>.run_in_context() running at D:\test\ipykernel\ipykernel\utils.py:60> wait_for=<Task pending name='Task-52017' coro=<Kernel.shell_main() running at D:\test\ipykernel\ipykernel\kernelbase.py:621> cb=[Task.task_wakeup()]> cb=[ZMQStream._run_callback.<locals>._log_error() at e:\.pixi\envs\default\Lib\site-packages\zmq\eventloop\zmqstream.py:563]>,
<Task pending name='Task-5217' coro=<Kernel.shell_main() running at D:\test\ipykernel\ipykernel\kernelbase.py:621> cb=[Task.task_wakeup()]>}
It keeps increasing task count and it wastes your some cpu resource in the background. It's acually running these below codes, it just enters the function the return repeatedly, by self.io_loop.call_later(0.001, advance_eventloop) of enter_eventloop() in kernelbase.py.
https://github.com/ipython/ipykernel/blob/8816d024bf730e9fdb051b44ab2fc1ee2276cea2/ipykernel/eventloops.py#L430-L473
How it happened:
The @register_integration("asyncio") and def loop_asyncio(kernel): was at the old ages, to drive the asyncio codes that inputed by users, like asyncio.ensure_future(...), when ipykernel was running under IOloop of tornado<6.1 which using the selectorloop or even older type eventloop. It was to make users able to run asyncio codes when the underhood is other things.
The current ipykernel its main loop is already asyncio loop, by IOloop of tornado>6.1. The user inputed asyncio codes already run in the main loop.
Therefore the related codes @register_integration("asyncio") and def loop_asyncio(kernel): could be deleted.
Solution:
related issue: https://github.com/ipython/ipykernel/pull/1469 solving the proactor and selector eventloop within asyncio
- 主要语言
- Python
- 星标
- 734
- 派生
- 411
- 平均合并
- 1 天 5 小时
- 30 天内合并 PR
- 8
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ipython/ipykernel 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 35/100
查看 ipython/ipykernel 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 74/100