Skip to content

Commit 1b243d3

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

File tree

8 files changed

+50
-54
lines changed

8 files changed

+50
-54
lines changed

ipykernel/debugger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def start(self):
423423
code += 'debugpy.listen(("' + host + '",' + port + "))"
424424
content = {"code": code, "silent": True}
425425

426-
#with open("debug.txt", "a") as f:
426+
# with open("debug.txt", "a") as f:
427427
# f.write(f"{threading.current_thread().ident} shell_socket execute_request\n")
428428

429429
self.session.send(

ipykernel/displayhook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __call__(self, obj):
4646
"metadata": {},
4747
}
4848

49-
#with open("debug.txt", "a") as f:
49+
# with open("debug.txt", "a") as f:
5050
# f.write(f"{threading.current_thread().ident} pub_socket execute_result\n")
5151

5252
self.session.send(
@@ -102,7 +102,7 @@ def finish_displayhook(self):
102102
sys.stdout.flush()
103103
sys.stderr.flush()
104104
if self.msg and self.msg["content"]["data"] and self.session:
105-
#with open("debug.txt", "a") as f:
105+
# with open("debug.txt", "a") as f:
106106
# f.write(f"{threading.current_thread().ident} pub_socket ?finish_displayhook\n")
107107

108108
self.session.send(self.pub_socket, self.msg, ident=self.topic)

ipykernel/iostream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ def __init__(self, socket, pipe=False):
7878
self.thread.is_pydev_daemon_thread = True # type:ignore[attr-defined]
7979
self.thread.name = "IOPub"
8080

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

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

87-
#with open("debug.txt", "a") as f:
87+
# with open("debug.txt", "a") as f:
8888
# f.write(f"{threading.current_thread().ident} IOPubThread._thread_main\n")
8989

9090
def _start_event_gc():
@@ -286,7 +286,7 @@ def _really_send(self, msg, *args, **kwargs):
286286
if self.closed:
287287
return
288288

289-
#with open("debug.txt", "a") as f:
289+
# with open("debug.txt", "a") as f:
290290
# f.write(f"{threading.current_thread().ident} _really_send iopub\n")
291291

292292
mp_mode = self._check_mp_mode()
@@ -655,7 +655,7 @@ def _flush(self):
655655
if msg is None:
656656
return
657657

658-
#with open("debug.txt", "a") as f:
658+
# with open("debug.txt", "a") as f:
659659
# f.write(f"{threading.current_thread().ident} pub_thread ?OutStream.flush\n")
660660

661661
self.session.send(

ipykernel/kernelbase.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def __init__(self, **kwargs):
277277
"""Initialize the kernel."""
278278
super().__init__(**kwargs)
279279

280-
#self._iant_lock = threading.Lock()
280+
# self._iant_lock = threading.Lock()
281281

282282
# Kernel application may swap stdout and stderr to OutStream,
283283
# which is the case in `IPKernelApp.init_io`, hence `sys.stdout`
@@ -425,7 +425,7 @@ async def dispatch_shell(self, msg, /, stream=None, subshell_id: str | None = No
425425
except Exception:
426426
self.log.debug("Unable to signal in pre_handler_hook:", exc_info=True)
427427
try:
428-
#result = handler(stream, idents, msg)
428+
# result = handler(stream, idents, msg)
429429
result = handler(self.shell_stream, idents, msg)
430430
if inspect.isawaitable(result):
431431
await result
@@ -575,7 +575,7 @@ def schedule_dispatch(self, dispatch, *args):
575575
def start(self):
576576
"""register dispatchers for streams"""
577577

578-
#with open("debug.txt", "a") as f:
578+
# with open("debug.txt", "a") as f:
579579
# f.write(f"--- kernelbase start --- {threading.main_thread().ident}\n")
580580

581581
self.io_loop = ioloop.IOLoop.current()
@@ -616,7 +616,7 @@ async def shell_channel_thread_main(self, msg):
616616
msg3 = self.session.deserialize(msg2, content=False, copy=False)
617617
subshell_id = msg3["header"].get("subshell_id")
618618

619-
#with open("debug.txt", "a") as f:
619+
# with open("debug.txt", "a") as f:
620620
# f.write(
621621
# f"{threading.current_thread().ident} shell_channel_thread_main msg received for {subshell_id}\n"
622622
# )
@@ -635,7 +635,7 @@ async def shell_channel_thread_main(self, msg):
635635
async def shell_main(self, subshell_id: str | None, msg):
636636
"""Handler of shell messages for a single subshell"""
637637

638-
#with open("debug.txt", "a") as f:
638+
# with open("debug.txt", "a") as f:
639639
# f.write(f"{threading.current_thread().ident} shell_main msg recvd on {subshell_id}\n")
640640

641641
if self._supports_kernel_subshells:
@@ -683,8 +683,8 @@ def _publish_execute_input(self, code, parent, execution_count):
683683
"""Publish the code request on the iopub stream."""
684684
if not self.session:
685685
return
686-
#with self._iant_lock:
687-
#with open("debug.txt", "a") as f:
686+
# with self._iant_lock:
687+
# with open("debug.txt", "a") as f:
688688
# f.write(f"{threading.current_thread().ident} iopub_socket execute_input\n")
689689

690690
self.session.send(
@@ -699,8 +699,8 @@ def _publish_status(self, status, channel, parent=None):
699699
"""send status (busy/idle) on IOPub"""
700700
if not self.session:
701701
return
702-
#with self._iant_lock:
703-
#with open("debug.txt", "a") as f:
702+
# with self._iant_lock:
703+
# with open("debug.txt", "a") as f:
704704
# f.write(f"{threading.current_thread().ident} iopub_socket status {status}\n")
705705
# f.write(f"SESSION {self.session}\n")
706706

@@ -721,8 +721,8 @@ def _publish_status_and_flush(self, status, channel, stream, parent=None):
721721
def _publish_debug_event(self, event):
722722
if not self.session:
723723
return
724-
#with self._iant_lock:
725-
#with open("debug.txt", "a") as f:
724+
# with self._iant_lock:
725+
# with open("debug.txt", "a") as f:
726726
# f.write(f"{threading.current_thread().ident} iopub_socket debug_event\n")
727727

728728
self.session.send(
@@ -793,7 +793,7 @@ def send_response(
793793
if not self.session:
794794
return None
795795

796-
#with open("debug.txt", "a") as f:
796+
# with open("debug.txt", "a") as f:
797797
# f.write(f"{threading.current_thread().ident} ? ?send_response\n")
798798

799799
return self.session.send(
@@ -871,7 +871,7 @@ async def execute_request(self, stream, ident, parent):
871871
subshell_id = parent["header"].get("subshell_id")
872872
msg_id = parent["header"].get("msg_id")
873873

874-
#with open("debug.txt", "a") as f:
874+
# with open("debug.txt", "a") as f:
875875
# f.write(
876876
# f"{threading.current_thread().ident} about to execute_request {msg_id} {subshell_id} {code}\n"
877877
# )
@@ -895,7 +895,7 @@ async def execute_request(self, stream, ident, parent):
895895
reply_content = json_clean(reply_content)
896896
metadata = self.finish_metadata(parent, metadata, reply_content)
897897

898-
#with open("debug.txt", "a") as f:
898+
# with open("debug.txt", "a") as f:
899899
# f.write(
900900
# f"{threading.current_thread().ident} execute_reply {msg_id} {subshell_id} {reply_content}\n"
901901
# )
@@ -990,7 +990,7 @@ async def history_request(self, stream, ident, parent):
990990

991991
reply_content = json_clean(reply_content)
992992

993-
#with open("debug.txt", "a") as f:
993+
# with open("debug.txt", "a") as f:
994994
# f.write(f"{threading.current_thread().ident} ? history_reply\n")
995995

996996
msg = self.session.send(stream, "history_reply", reply_content, parent, ident)
@@ -1018,7 +1018,7 @@ async def connect_request(self, stream, ident, parent):
10181018
content = self._recorded_ports.copy() if self._recorded_ports else {}
10191019
content["status"] = "ok"
10201020

1021-
#with open("debug.txt", "a") as f:
1021+
# with open("debug.txt", "a") as f:
10221022
# f.write(f"{threading.current_thread().ident} ? connect_reply\n")
10231023

10241024
msg = self.session.send(stream, "connect_reply", content, parent, ident)
@@ -1046,7 +1046,7 @@ async def kernel_info_request(self, stream, ident, parent):
10461046
content = {"status": "ok"}
10471047
content.update(self.kernel_info)
10481048

1049-
#with open("debug.txt", "a") as f:
1049+
# with open("debug.txt", "a") as f:
10501050
# f.write(f"{threading.current_thread().ident} ? kernel_info_reply\n")
10511051

10521052
msg = self.session.send(stream, "kernel_info_reply", content, parent, ident)
@@ -1117,7 +1117,7 @@ async def shutdown_request(self, stream, ident, parent):
11171117
if inspect.isawaitable(content):
11181118
content = await content
11191119

1120-
#with open("debug.txt", "a") as f:
1120+
# with open("debug.txt", "a") as f:
11211121
# f.write(f"{threading.current_thread().ident} ? shutdown_reply\n")
11221122

11231123
self.session.send(stream, "shutdown_reply", content, parent, ident=ident)
@@ -1171,7 +1171,7 @@ async def debug_request(self, stream, ident, parent):
11711171
reply_content = await reply_content
11721172
reply_content = json_clean(reply_content)
11731173

1174-
#with open("debug.txt", "a") as f:
1174+
# with open("debug.txt", "a") as f:
11751175
# f.write(f"{threading.current_thread().ident} ? debug_reply\n")
11761176

11771177
reply_msg = self.session.send(stream, "debug_reply", reply_content, parent, ident)
@@ -1236,7 +1236,7 @@ async def create_subshell_request(self, socket, ident, parent) -> None:
12361236
self.log.error("Subshells are not supported by this kernel")
12371237
return
12381238

1239-
#with open("debug.txt", "a") as f:
1239+
# with open("debug.txt", "a") as f:
12401240
# f.write(f"{threading.current_thread().ident} ? create_subshell_request\n")
12411241

12421242
assert threading.current_thread().name == CONTROL_THREAD_NAME
@@ -1247,7 +1247,7 @@ async def create_subshell_request(self, socket, ident, parent) -> None:
12471247
other_socket.send_json({"type": "create"})
12481248
reply = other_socket.recv_json()
12491249

1250-
#with open("debug.txt", "a") as f:
1250+
# with open("debug.txt", "a") as f:
12511251
# f.write(f"{threading.current_thread().ident} ? create_subshell_reply\n")
12521252

12531253
self.session.send(socket, "create_subshell_reply", reply, parent, ident)
@@ -1274,7 +1274,7 @@ async def delete_subshell_request(self, socket, ident, parent) -> None:
12741274
other_socket.send_json({"type": "delete", "subshell_id": subshell_id})
12751275
reply = other_socket.recv_json()
12761276

1277-
#with open("debug.txt", "a") as f:
1277+
# with open("debug.txt", "a") as f:
12781278
# f.write(f"{threading.current_thread().ident} ? delete_subshell_reply\n")
12791279

12801280
self.session.send(socket, "delete_subshell_reply", reply, parent, ident)
@@ -1294,7 +1294,7 @@ async def list_subshell_request(self, socket, ident, parent) -> None:
12941294
other_socket.send_json({"type": "list"})
12951295
reply = other_socket.recv_json()
12961296

1297-
#with open("debug.txt", "a") as f:
1297+
# with open("debug.txt", "a") as f:
12981298
# f.write(f"{threading.current_thread().ident} ? list_subshell_reply\n")
12991299

13001300
self.session.send(socket, "list_subshell_reply", reply, parent, ident)
@@ -1362,7 +1362,7 @@ async def abort_request(self, stream, ident, parent): # pragma: no cover
13621362
if not self.session:
13631363
return
13641364

1365-
#with open("debug.txt", "a") as f:
1365+
# with open("debug.txt", "a") as f:
13661366
# f.write(f"{threading.current_thread().ident} ? abort_reply\n")
13671367

13681368
reply_msg = self.session.send(
@@ -1463,7 +1463,7 @@ def _send_abort_reply(self, stream, msg, idents):
14631463
md = self.finish_metadata(msg, md, status)
14641464
md.update(status)
14651465

1466-
#with open("debug.txt", "a") as f:
1466+
# with open("debug.txt", "a") as f:
14671467
# f.write(f"{threading.current_thread().ident} ? {reply_type}\n")
14681468

14691469
self.session.send(
@@ -1646,8 +1646,8 @@ async def _at_shutdown(self):
16461646

16471647
finally:
16481648
if self._shutdown_message is not None and self.session:
1649-
#with self._iant_lock:
1650-
#with open("debug.txt", "a") as f:
1649+
# with self._iant_lock:
1650+
# with open("debug.txt", "a") as f:
16511651
# f.write(f"{threading.current_thread().ident} ? _shutdown\n")
16521652

16531653
self.session.send(

ipykernel/subshell_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ def _process_control_request(
224224
def _send_on_shell_channel(self, msg) -> None:
225225
assert current_thread().name == SHELL_CHANNEL_THREAD_NAME
226226

227-
#with open("debug.txt", "a") as f:
227+
# with open("debug.txt", "a") as f:
228228
# f.write(f"{current_thread().ident} _send_on_shell_channel - start {msg}\n")
229229

230230
with self._lock_shell_socket:
231-
#with open("debug.txt", "a") as f:
231+
# with open("debug.txt", "a") as f:
232232
# f.write(f" {self._shell_socket}\n")
233233
self._shell_socket.send_multipart(msg)
234234

235-
#with open("debug.txt", "a") as f:
235+
# with open("debug.txt", "a") as f:
236236
# f.write(f"{current_thread().ident} _send_on_shell_channel - end\n")
237237

238238
def _stop_subshell(self, subshell_thread: SubshellThread) -> None:

ipykernel/thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, **kwargs):
2323
def run(self) -> None:
2424
"""Run the thread."""
2525
try:
26-
#with open("debug.txt", "a") as f:
26+
# with open("debug.txt", "a") as f:
2727
# f.write(f"{threading.current_thread().ident} io_loop - about to start\n")
2828

2929
self.io_loop.start()

tests/test_subshells.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_subshell_helper(kc: BlockingKernelClient):
2020
kc.control_channel.send(msg)
2121
msg_id = msg["header"]["msg_id"]
2222
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
23-
#wait_for_idle(kc, msg_id)
23+
# wait_for_idle(kc, msg_id)
2424
return reply["content"]
2525

2626

@@ -29,7 +29,7 @@ def delete_subshell_helper(kc: BlockingKernelClient, subshell_id: str):
2929
kc.control_channel.send(msg)
3030
msg_id = msg["header"]["msg_id"]
3131
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
32-
#wait_for_idle(kc, msg_id)
32+
# wait_for_idle(kc, msg_id)
3333
return reply["content"]
3434

3535

@@ -38,7 +38,7 @@ def list_subshell_helper(kc: BlockingKernelClient):
3838
kc.control_channel.send(msg)
3939
msg_id = msg["header"]["msg_id"]
4040
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
41-
#wait_for_idle(kc, msg_id)
41+
# wait_for_idle(kc, msg_id)
4242
return reply["content"]
4343

4444

@@ -52,23 +52,22 @@ def execute_request(kc: BlockingKernelClient, code: str, subshell_id: str | None
5252
def execute_request_subshell_id(
5353
kc: BlockingKernelClient, code: str, subshell_id: str | None, terminator: str = "\n"
5454
):
55-
56-
#with open("debug.txt", "a") as f:
55+
# with open("debug.txt", "a") as f:
5756
# f.write("CHECK 1\n")
5857

5958
msg = execute_request(kc, code, subshell_id)
6059

61-
#with open("debug.txt", "a") as f:
60+
# with open("debug.txt", "a") as f:
6261
# f.write("CHECK 2\n")
6362

6463
msg_id = msg["header"]["msg_id"]
6564

66-
#with open("debug.txt", "a") as f:
65+
# with open("debug.txt", "a") as f:
6766
# f.write("CHECK 3\n")
6867

6968
stdout, _ = assemble_output(kc.get_iopub_msg, None, msg_id)
7069

71-
#with open("debug.txt", "a") as f:
70+
# with open("debug.txt", "a") as f:
7271
# f.write("CHECK 4\n")
7372

7473
return stdout.strip()
@@ -126,7 +125,7 @@ def test_thread_ids():
126125
thread_id, main_thread_id = execute_thread_ids(kc)
127126
assert thread_id == main_thread_id
128127

129-
thread_id, main_thread_id = execute_thread_ids(kc, subshell_id) # This is the problem
128+
thread_id, main_thread_id = execute_thread_ids(kc, subshell_id) # This is the problem
130129
assert thread_id != main_thread_id
131130

132131
delete_subshell_helper(kc, subshell_id)

0 commit comments

Comments
 (0)