Removing `@register_integration("asyncio")` and `def loop_asyncio(kernel):`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
Research direction
Start with ipykernel/eventloops.py around the linked integration code and trace how it is invoked from enter_eventloop() in kernelbase.py. Compare the behavior with the asyncio event-loop changes described in pull request 1469, then verify that repeated %gui asyncio execution no longer causes the asyncio task count to grow or wastes CPU.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 734
- Forks
- 411
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ipython/ipykernel
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
-
ipython/ipykernel#1550 · 1 comment · 1 reaction · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in ipython/ipykernel
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100