Skip to content

Commit 7986de5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f4c4167 commit 7986de5

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

ipykernel/debugger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
except ImportError:
1818
from jupyter_client.jsonutil import date_default as json_default
1919

20-
from .compiler import get_file_name, get_tmp_directory, get_tmp_hash_seed
21-
2220
import threading
2321

22+
from .compiler import get_file_name, get_tmp_directory, get_tmp_hash_seed
23+
2424
try:
2525
# This import is required to have the next ones working...
2626
from debugpy.server import api # noqa: F401

ipykernel/displayhook.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import builtins
88
import sys
9+
import threading
910
import typing as t
1011

1112
from IPython.core.displayhook import DisplayHook
@@ -15,9 +16,6 @@
1516
from ipykernel.jsonutil import encode_images, json_clean
1617

1718

18-
import threading
19-
20-
2119
class ZMQDisplayHook:
2220
"""A simple displayhook that publishes the object's repr over a ZeroMQ
2321
socket."""
@@ -104,7 +102,6 @@ def finish_displayhook(self):
104102
sys.stdout.flush()
105103
sys.stderr.flush()
106104
if self.msg and self.msg["content"]["data"] and self.session:
107-
108105
with open("debug.txt", "a") as f:
109106
f.write(f"{threading.current_thread().ident} pub_socket ?finish_displayhook\n")
110107

ipykernel/iostream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, socket, pipe=False):
7979
self.thread.name = "IOPub"
8080

8181
with open("debug.txt", "a") as f:
82-
f.write(f" IOPubThread.__init__\n")
82+
f.write(" IOPubThread.__init__\n")
8383

8484
def _thread_main(self):
8585
"""The inner loop that's actually run in a thread"""

ipykernel/kernelbase.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _accepts_parameters(meth, param_names):
7979

8080
class Kernel(SingletonConfigurable):
8181
"""The base kernel class."""
82+
8283
# ---------------------------------------------------------------------------
8384
# Kernel interface
8485
# ---------------------------------------------------------------------------
@@ -276,12 +277,8 @@ def __init__(self, **kwargs):
276277
"""Initialize the kernel."""
277278
super().__init__(**kwargs)
278279

279-
280-
281280
self._iant_lock = threading.Lock()
282281

283-
284-
285282
# Kernel application may swap stdout and stderr to OutStream,
286283
# which is the case in `IPKernelApp.init_io`, hence `sys.stdout`
287284
# can already by different from TextIO at initialization time.
@@ -619,7 +616,9 @@ async def shell_channel_thread_main(self, msg):
619616
subshell_id = msg3["header"].get("subshell_id")
620617

621618
with open("debug.txt", "a") as f:
622-
f.write(f"{threading.current_thread().ident} shell_channel_thread_main msg received for {subshell_id}\n")
619+
f.write(
620+
f"{threading.current_thread().ident} shell_channel_thread_main msg received for {subshell_id}\n"
621+
)
623622

624623
# Find inproc pair socket to use to send message to correct subshell.
625624
subshell_manager = self.shell_channel_thread.manager
@@ -684,7 +683,6 @@ def _publish_execute_input(self, code, parent, execution_count):
684683
if not self.session:
685684
return
686685
with self._iant_lock:
687-
688686
with open("debug.txt", "a") as f:
689687
f.write(f"{threading.current_thread().ident} iopub_socket execute_input\n")
690688

@@ -701,7 +699,6 @@ def _publish_status(self, status, channel, parent=None):
701699
if not self.session:
702700
return
703701
with self._iant_lock:
704-
705702
with open("debug.txt", "a") as f:
706703
f.write(f"{threading.current_thread().ident} iopub_socket status {status}\n")
707704

@@ -723,7 +720,6 @@ def _publish_debug_event(self, event):
723720
if not self.session:
724721
return
725722
with self._iant_lock:
726-
727723
with open("debug.txt", "a") as f:
728724
f.write(f"{threading.current_thread().ident} iopub_socket debug_event\n")
729725

@@ -870,12 +866,13 @@ async def execute_request(self, stream, ident, parent):
870866
if self._do_exec_accepted_params["cell_id"]:
871867
do_execute_args["cell_id"] = cell_id
872868

873-
874869
subshell_id = parent["header"].get("subshell_id")
875870
msg_id = parent["header"].get("msg_id")
876871

877872
with open("debug.txt", "a") as f:
878-
f.write(f"{threading.current_thread().ident} about to execute_request {msg_id} {subshell_id} {code}\n")
873+
f.write(
874+
f"{threading.current_thread().ident} about to execute_request {msg_id} {subshell_id} {code}\n"
875+
)
879876

880877
# Call do_execute with the appropriate arguments
881878
reply_content = self.do_execute(**do_execute_args)
@@ -897,7 +894,9 @@ async def execute_request(self, stream, ident, parent):
897894
metadata = self.finish_metadata(parent, metadata, reply_content)
898895

899896
with open("debug.txt", "a") as f:
900-
f.write(f"{threading.current_thread().ident} execute_reply {msg_id} {subshell_id}\n")
897+
f.write(
898+
f"{threading.current_thread().ident} execute_reply {msg_id} {subshell_id}\n"
899+
)
901900

902901
reply_msg: dict[str, t.Any] = self.session.send( # type:ignore[assignment]
903902
stream,
@@ -1643,7 +1642,6 @@ async def _at_shutdown(self):
16431642
finally:
16441643
if self._shutdown_message is not None and self.session:
16451644
with self._iant_lock:
1646-
16471645
with open("debug.txt", "a") as f:
16481646
f.write(f"{threading.current_thread().ident} ? _shutdown\n")
16491647

tests/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,19 @@ def new_kernel(argv=None):
172172
return manager.run_kernel(**kwargs)
173173

174174

175-
def assemble_output(get_msg, timeout=1, parent_msg_id: str | None=None):
175+
def assemble_output(get_msg, timeout=1, parent_msg_id: str | None = None):
176176
"""assemble stdout/err from an execution"""
177177
stdout = ""
178178
stderr = ""
179179
while True:
180180
msg = get_msg(timeout=timeout)
181181
msg_type = msg["msg_type"]
182182
content = msg["content"]
183-
if msg_type == "status" and content["execution_state"] == "idle" and (parent_msg_id is None or msg["parent_header"]["msg_id"] == parent_msg_id):
183+
if (
184+
msg_type == "status"
185+
and content["execution_state"] == "idle"
186+
and (parent_msg_id is None or msg["parent_header"]["msg_id"] == parent_msg_id)
187+
):
184188
# idle message signals end of output
185189
break
186190
elif msg["msg_type"] == "stream":
@@ -196,12 +200,16 @@ def assemble_output(get_msg, timeout=1, parent_msg_id: str | None=None):
196200
return stdout, stderr
197201

198202

199-
def wait_for_idle(kc, parent_msg_id: str | None=None):
203+
def wait_for_idle(kc, parent_msg_id: str | None = None):
200204
while True:
201205
msg = kc.get_iopub_msg(timeout=1)
202206
msg_type = msg["msg_type"]
203207
content = msg["content"]
204-
if msg_type == "status" and content["execution_state"] == "idle" and (parent_msg_id is None or msg['parent_header']['msg_id'] == parent_msg_id):
208+
if (
209+
msg_type == "status"
210+
and content["execution_state"] == "idle"
211+
and (parent_msg_id is None or msg["parent_header"]["msg_id"] == parent_msg_id)
212+
):
205213
break
206214

207215

0 commit comments

Comments
 (0)