|
16 | 16 | from io import FileIO, TextIOWrapper |
17 | 17 | from logging import StreamHandler |
18 | 18 | from pathlib import Path |
| 19 | +from typing import Optional |
19 | 20 |
|
20 | 21 | import zmq |
21 | 22 | from IPython.core.application import ( # type:ignore[attr-defined] |
@@ -141,8 +142,9 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix |
141 | 142 | debug_shell_socket = Any() |
142 | 143 | stdin_socket = Any() |
143 | 144 | iopub_socket = Any() |
144 | | - iopub_thread = Any() |
145 | | - control_thread = Any() |
| 145 | + |
| 146 | + iopub_thread: Optional[IOPubThread] = Instance(IOPubThread, allow_none=True) # type:ignore[assignment] |
| 147 | + control_thread: Optional[ControlThread] = Instance(ControlThread, allow_none=True) # type:ignore[assignment] |
146 | 148 |
|
147 | 149 | _ports = Dict() |
148 | 150 |
|
@@ -259,7 +261,7 @@ def _bind_socket(self, s, port): |
259 | 261 | raise |
260 | 262 | return None |
261 | 263 |
|
262 | | - def write_connection_file(self): |
| 264 | + def write_connection_file(self, **kwargs: t.Any) -> None: |
263 | 265 | """write connection info to JSON file""" |
264 | 266 | cf = self.abs_connection_file |
265 | 267 | connection_info = dict( |
@@ -398,11 +400,11 @@ def close(self): |
398 | 400 | if self.heartbeat: |
399 | 401 | self.log.debug("Closing heartbeat channel") |
400 | 402 | self.heartbeat.context.term() |
401 | | - if self.iopub_thread: |
| 403 | + if self.iopub_thread is not None: |
402 | 404 | self.log.debug("Closing iopub channel") |
403 | 405 | self.iopub_thread.stop() |
404 | 406 | self.iopub_thread.close() |
405 | | - if self.control_thread and self.control_thread.is_alive(): |
| 407 | + if self.control_thread is not None and self.control_thread.is_alive(): |
406 | 408 | self.log.debug("Closing control thread") |
407 | 409 | self.control_thread.stop() |
408 | 410 | self.control_thread.join() |
|
0 commit comments