Skip to content

Commit c349a91

Browse files
committed
Misc cleanup and types updates
1 parent 314cc49 commit c349a91

File tree

2 files changed

+64
-16
lines changed

2 files changed

+64
-16
lines changed

ipykernel/kernelapp.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from io import FileIO, TextIOWrapper
1717
from logging import StreamHandler
1818
from pathlib import Path
19+
from threading import Thread
1920

2021
import zmq
2122
import zmq.asyncio
@@ -142,9 +143,9 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
142143
debug_shell_socket = Any()
143144
stdin_socket = Any()
144145
iopub_socket = Any()
145-
iopub_thread = Any()
146-
control_thread = Any()
147-
shell_channel_thread = Any()
146+
iopub_thread: Thread
147+
control_thread: Thread
148+
shell_channel_thread: Thread
148149

149150
_ports = Dict()
150151

ipykernel/kernelbase.py

+60-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import warnings
1818
from datetime import datetime
1919
from signal import SIGINT, SIGTERM, Signals
20+
from threading import Thread
2021

2122
from .thread import CONTROL_THREAD_NAME
2223

@@ -95,17 +96,16 @@ class Kernel(SingletonConfigurable):
9596
implementation_version: str
9697
banner: str
9798

98-
_is_test = Bool(False)
99+
_is_test: bool = False
99100

100101
control_socket = Instance(zmq.asyncio.Socket, allow_none=True)
101102
control_tasks: t.Any = List()
102103

103104
debug_shell_socket = Any()
105+
control_thread: Thread
106+
shell_channel_thread: Thread
104107

105-
control_thread = Any()
106-
shell_channel_thread = Any()
107108
iopub_socket = Any()
108-
iopub_thread = Any()
109109
stdin_socket = Any()
110110
log: logging.Logger = Instance(logging.Logger, allow_none=True) # type:ignore[assignment]
111111

@@ -217,6 +217,9 @@ def _parent_header(self):
217217
"shutdown_request",
218218
"is_complete_request",
219219
"interrupt_request",
220+
# I have the impression that there is amix/match debug_request and do_debug_request
221+
# former was from ipyparallel but is marked as deprecated, but now call do_debug_request
222+
# "do_debug_request"
220223
# deprecated:
221224
"apply_request",
222225
]
@@ -258,6 +261,17 @@ def __init__(self, **kwargs):
258261
self.do_execute, ["cell_meta", "cell_id"]
259262
)
260263

264+
if not inspect.iscoroutinefunction(self.do_debug_request):
265+
# warning at init time, as we want to warn early enough, even if the
266+
# function is not called
267+
warnings.warn(
268+
"`do_debug_request` will be required to be a coroutine "
269+
"functions in the future. coroutine functions have ben supported "
270+
"since ipykernel 6.0 (2021)",
271+
DeprecationWarning,
272+
stacklevel=2,
273+
)
274+
261275
async def process_control(self):
262276
try:
263277
while True:
@@ -1007,13 +1021,35 @@ def do_is_complete(self, code):
10071021
return {"status": "unknown"}
10081022

10091023
async def debug_request(self, socket, ident, parent):
1010-
"""Handle a debug request."""
1024+
"""Handle a debug request.
1025+
1026+
Seem Deprecated
1027+
"""
1028+
# If this is incorrect, remove `debug_request` from the deprecated message types
1029+
# at the beginning of this class
1030+
warnings.warn(
1031+
"debug_request is deprecated in kernel_base since ipykernel 6.10"
1032+
" (2022). It is only part of IPython parallel. Did you mean do_debug_request ?",
1033+
DeprecationWarning,
1034+
stacklevel=2,
1035+
)
10111036
if not self.session:
10121037
return
10131038
content = parent["content"]
1014-
reply_content = self.do_debug_request(content)
1015-
if inspect.isawaitable(reply_content):
1016-
reply_content = await reply_content
1039+
if not inspect.iscoroutinefunction(self.do_debug_request):
1040+
# repeat the warning at run
1041+
reply_content = self.do_debug_request(content)
1042+
warnings.warn(
1043+
"`do_debug_request` will be required to be a coroutine "
1044+
"functions in the future. coroutine functions have ben supported "
1045+
"since ipykernel 6.0 (2021)",
1046+
DeprecationWarning,
1047+
stacklevel=1,
1048+
)
1049+
if inspect.isawaitable(reply_content):
1050+
reply_content = await reply_content
1051+
else:
1052+
reply_content = await self.do_debug_request(content)
10171053
reply_content = json_clean(reply_content)
10181054
reply_msg = self.session.send(socket, "debug_reply", reply_content, parent, ident)
10191055
self.log.debug("%s", reply_msg)
@@ -1132,7 +1168,12 @@ async def list_subshell_request(self, socket, ident, parent) -> None:
11321168

11331169
async def apply_request(self, socket, ident, parent): # pragma: no cover
11341170
"""Handle an apply request."""
1135-
self.log.warning("apply_request is deprecated in kernel_base, moving to ipyparallel.")
1171+
warnings.warn(
1172+
"apply_request is deprecated in kernel_base since"
1173+
" IPykernel 6.10 (2022) , moving to ipyparallel.",
1174+
DeprecationWarning,
1175+
stacklevel=2,
1176+
)
11361177
try:
11371178
content = parent["content"]
11381179
bufs = parent["buffers"]
@@ -1174,8 +1215,11 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
11741215

11751216
async def abort_request(self, socket, ident, parent): # pragma: no cover
11761217
"""abort a specific msg by id"""
1177-
self.log.warning(
1178-
"abort_request is deprecated in kernel_base. It is only part of IPython parallel"
1218+
warnings.warn(
1219+
"abort_request is deprecated in kernel_base since ipykernel 6.10"
1220+
" (2022). It is only part of IPython parallel",
1221+
DeprecationWarning,
1222+
stacklevel=2,
11791223
)
11801224
msg_ids = parent["content"].get("msg_ids", None)
11811225
if isinstance(msg_ids, str):
@@ -1193,8 +1237,11 @@ async def abort_request(self, socket, ident, parent): # pragma: no cover
11931237

11941238
async def clear_request(self, socket, idents, parent): # pragma: no cover
11951239
"""Clear our namespace."""
1196-
self.log.warning(
1197-
"clear_request is deprecated in kernel_base. It is only part of IPython parallel"
1240+
warnings.warn(
1241+
"clear_request is deprecated in kernel_base since IPykernel 6.10"
1242+
" (2022). It is only part of IPython parallel",
1243+
DeprecationWarning,
1244+
stacklevel=2,
11981245
)
11991246
content = self.do_clear()
12001247
if self.session:

0 commit comments

Comments
 (0)