Skip to content

Commit

Permalink
Maintenance updates (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jan 30, 2023
1 parent 4ce612a commit 1c64fef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
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)()
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
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

0 comments on commit 1c64fef

Please sign in to comment.