Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ def enter_eventloop(self):
self.log.info("Exiting as there is no eventloop")
return

from .eventloops import loop_asyncio

if eventloop is loop_asyncio:
# The kernel already runs on asyncio, so there is nothing to poll.
# Polling every millisecond would only burn CPU (#1532).
self.log.info("Kernel already runs on asyncio; no polling needed")
return

async def advance_eventloop():
# check if eventloop changed:
if self.eventloop is not eventloop:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ def do_thing():
loop_asyncio(kernel)


@windows_skip
async def test_asyncio_gui_does_not_poll(kernel):
# The kernel already runs on asyncio, so `%gui asyncio` has nothing to poll (#1532).
calls = []
call_later = kernel.io_loop.call_later

def counting_call_later(delay, callback, *args, **kwargs):
calls.append(callback)
return call_later(delay, callback, *args, **kwargs)

kernel.io_loop.call_later = counting_call_later
try:
kernel.eventloop = loop_asyncio
await asyncio.sleep(0.1)
finally:
kernel.eventloop = None
del kernel.io_loop.call_later
assert len(calls) <= 1


@windows_skip
def test_enable_gui(kernel):
enable_gui("tk", kernel)
Expand Down
Loading