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

Maintenance updates #1081

Merged
merged 2 commits into from
Jan 30, 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: 2 additions & 8 deletions ipykernel/eventloops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 @@ -250,12 +251,6 @@ 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 @@ -267,9 +262,8 @@ def __init__(self, app, func):
self.func = func

def on_timer(self):
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(self.func())
run_sync(self.func)()
Copy link
Member

@ccordoba12 ccordoba12 Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a Windows specific code path for which we don't have tests in Spyder-kernels.

@dalthviz, could you check that this PR doesn't break the Tk backend on Windows, as described in spyder-ide/spyder#17024? (see PR #830, which introduced this fix).

Also @impact27, if you're available, could you take a look at these changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I tested seems like this PR works with the latest Spyder 5.x branch on Windows with the Tkinter graphics backend and a custom interpreter 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dalthviz!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's wait until Tuesday to see if @impact27 has time to review this. If not, please go ahead and merge it @blink1073.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand run_sync uses asyncio so it should work as intended

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, thanks @impact27!

except Exception:
kernel.log.exception("Error in message handler")
self.app.after(poll_interval, self.on_timer)
Expand Down
6 changes: 1 addition & 5 deletions ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@

from jupyter_client.client import KernelClient
from jupyter_client.clientabc import KernelClientABC

try:
from jupyter_client.utils import run_sync # requires 7.0+
except ImportError:
run_sync = None # type:ignore
Comment on lines -18 to -22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the inline comment here, you need to bump the minimal required version of Jupyter-client in pyproject.toml to be >=7.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we're pulling this function from jupyter_core now, which I added to the deps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see 👍🏽 Sorry for the noise then.

from jupyter_core.utils import run_sync

# IPython imports
from traitlets import Instance, Type, default
Expand Down
6 changes: 4 additions & 2 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from functools import partial
from io import FileIO, TextIOWrapper
from logging import StreamHandler
from typing import Optional

import zmq
from IPython.core.application import ( # type:ignore[attr-defined]
Expand Down Expand Up @@ -131,7 +132,7 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
poller = Any() # don't restrict this even though current pollers are all Threads
heartbeat = Instance(Heartbeat, allow_none=True)

context = Any()
context: Optional[zmq.Context] = Any() # type:ignore[assignment]
shell_socket = Any()
control_socket = Any()
debugpy_socket = Any()
Expand Down Expand Up @@ -403,7 +404,8 @@ def close(self):
if socket and not socket.closed:
socket.close()
self.log.debug("Terminating zmq context")
self.context.term()
if self.context:
self.context.term()
self.log.debug("Terminated zmq context")

def log_connection_info(self):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ dependencies = [
"comm>=0.1.1",
"traitlets>=5.4.0",
"jupyter_client>=6.1.12",
"jupyter_core>=4.12,!=5.0.*",
"tornado>=6.1",
"matplotlib-inline>=0.1",
'appnope;platform_system=="Darwin"',
"pyzmq>=17",
"psutil",
"nest_asyncio",
"packaging",
]

Expand Down