ipython / ipython/ipykernel

Removing `@register_integration("asyncio")` and `def loop_asyncio(kernel):`

未关闭
#1,532 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
734
派生
412
平均合并
1 天 5 小时
30 天内合并 PR
8

描述

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
```
{.run_in_context() running at D:\test\ipykernel\ipykernel\utils.py:60> wait_for= cb=[Task.task_wakeup()]> cb=[ZMQStream._run_callback.._log_error() at e:\.pixi\envs\default\Lib\site-packages\zmq\eventloop\zmqstream.py:563]>,
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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。