Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore nest-asyncio for tk loop #1086

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
10 changes: 8 additions & 2 deletions ipykernel/eventloops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from functools import partial

import zmq
from jupyter_core.utils import run_sync
from packaging.version import Version as V # noqa
from traitlets.config.application import Application

Expand Down Expand Up @@ -251,6 +250,12 @@ def process_stream_events(stream, *a, **kw):
app.mainloop()

else:
import asyncio

import nest_asyncio

nest_asyncio.apply()

doi = kernel.do_one_iteration
# Tk uses milliseconds
poll_interval = int(1000 * kernel._poll_interval)
Expand All @@ -262,8 +267,9 @@ def __init__(self, app, func):
self.func = func

def on_timer(self):
loop = asyncio.get_event_loop()
try:
run_sync(self.func)()
loop.run_until_complete(self.func())
except Exception:
kernel.log.exception("Error in message handler")
self.app.after(poll_interval, self.on_timer)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies = [
"traitlets>=5.4.0",
"jupyter_client>=6.1.12",
"jupyter_core>=4.12,!=5.0.*",
# For tk event loop support only.
"nest_asyncio",
"tornado>=6.1",
"matplotlib-inline>=0.1",
'appnope;platform_system=="Darwin"',
Expand Down