|
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 | import zmq.asyncio
|
|
54 | 55 | from .ipkernel import IPythonKernel
|
55 | 56 | from .parentpoller import ParentPollerUnix, ParentPollerWindows
|
56 | 57 | from .shellchannel import ShellChannelThread
|
| 58 | +from .thread import BaseThread |
57 | 59 | from .zmqshell import ZMQInteractiveShell
|
58 | 60 |
|
59 | 61 | # -----------------------------------------------------------------------------
|
@@ -142,9 +144,10 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
|
142 | 144 | debug_shell_socket = Any()
|
143 | 145 | stdin_socket = Any()
|
144 | 146 | iopub_socket = Any()
|
145 |
| - iopub_thread = Any() |
146 |
| - control_thread = Any() |
147 |
| - shell_channel_thread = Any() |
| 147 | + |
| 148 | + iopub_thread: Optional[IOPubThread] = Instance(IOPubThread, allow_none=True) # type:ignore[assignment] |
| 149 | + control_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment] |
| 150 | + shell_channel_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment] |
148 | 151 |
|
149 | 152 | _ports = Dict()
|
150 | 153 |
|
@@ -261,7 +264,7 @@ def _bind_socket(self, s, port):
|
261 | 264 | raise
|
262 | 265 | return None
|
263 | 266 |
|
264 |
| - def write_connection_file(self): |
| 267 | + def write_connection_file(self, **kwargs: t.Any) -> None: |
265 | 268 | """write connection info to JSON file"""
|
266 | 269 | cf = self.abs_connection_file
|
267 | 270 | connection_info = dict(
|
@@ -401,15 +404,15 @@ def close(self):
|
401 | 404 | if self.heartbeat:
|
402 | 405 | self.log.debug("Closing heartbeat channel")
|
403 | 406 | self.heartbeat.context.term()
|
404 |
| - if self.iopub_thread: |
| 407 | + if self.iopub_thread is not None: |
405 | 408 | self.log.debug("Closing iopub channel")
|
406 | 409 | self.iopub_thread.stop()
|
407 | 410 | self.iopub_thread.close()
|
408 |
| - if self.control_thread and self.control_thread.is_alive(): |
| 411 | + if self.control_thread is not None and self.control_thread.is_alive(): |
409 | 412 | self.log.debug("Closing control thread")
|
410 | 413 | self.control_thread.stop()
|
411 | 414 | self.control_thread.join()
|
412 |
| - if self.shell_channel_thread and self.shell_channel_thread.is_alive(): |
| 415 | + if self.shell_channel_thread is not None and self.shell_channel_thread.is_alive(): |
413 | 416 | self.log.debug("Closing shell channel thread")
|
414 | 417 | self.shell_channel_thread.stop()
|
415 | 418 | self.shell_channel_thread.join()
|
|
0 commit comments