Skip to content

Commit 960ff5a

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

File tree

9 files changed

+24
-48
lines changed

9 files changed

+24
-48
lines changed

ipykernel/athread.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import asyncio
2-
import inspect
32
import threading
43

54
import janus
65

76

87
class AThread(threading.Thread):
9-
"""A thread that can run async tasks.
10-
"""
8+
"""A thread that can run async tasks."""
119

1210
def __init__(self, name, awaitables=[]):
1311
super().__init__(name=name, daemon=True)
@@ -40,17 +38,15 @@ async def _main(self):
4038
task.cancel()
4139

4240
def create_task(self, awaitable):
43-
"""Create a task in the thread (thread-safe).
44-
"""
41+
"""Create a task in the thread (thread-safe)."""
4542
with self._lock:
4643
if self.__initialized:
4744
self._queue.sync_q.put(awaitable)
4845
else:
4946
self._aws.append(awaitable)
5047

5148
def stop(self):
52-
"""Stop the thread (thread-safe).
53-
"""
49+
"""Stop the thread (thread-safe)."""
5450
with self._lock:
5551
if self.__initialized:
5652
self._queue.sync_q.put(None)

ipykernel/inprocess/ipkernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InProcessKernel(IPythonKernel):
5151
_underlying_iopub_socket = Instance(DummySocket, ())
5252
iopub_thread: IOPubThread = Instance(IOPubThread) # type:ignore[assignment]
5353

54-
#shell_stream = Instance(DummySocket, ())
54+
# shell_stream = Instance(DummySocket, ())
5555

5656
@default("iopub_thread")
5757
def _default_iopub_thread(self):

ipykernel/iostream.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, socket, pipe=False):
6565
self._events: Deque[Callable[..., Any]] = deque()
6666
self._event_pipes: WeakSet[Any] = WeakSet()
6767
self._setup_event_pipe()
68-
#self.thread = threading.Thread(target=self._thread_main, name="IOPub")
68+
# self.thread = threading.Thread(target=self._thread_main, name="IOPub")
6969
aws = [self._handle_event()]
7070
if self._pipe_flag:
7171
aws.append(self._handle_pipe_msg())
@@ -169,7 +169,7 @@ def _check_mp_mode(self):
169169

170170
def start(self):
171171
"""Start the IOPub thread"""
172-
#self.thread.name = "IOPub"
172+
# self.thread.name = "IOPub"
173173
self.thread.start()
174174
# make sure we don't prevent process exit
175175
# I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be.
@@ -179,7 +179,7 @@ def stop(self):
179179
"""Stop the IOPub thread"""
180180
if not self.thread.is_alive():
181181
return
182-
#self.io_loop.call_soon_threadsafe(self.io_loop.stop)
182+
# self.io_loop.call_soon_threadsafe(self.io_loop.stop)
183183
self.thread.stop()
184184
self.thread.join()
185185
# close *all* event pipes, created in any thread
@@ -210,9 +210,9 @@ def schedule(self, f):
210210
if self.thread.is_alive():
211211
self._events.append(f)
212212
# wake event thread (message content is ignored)
213-
#try:
213+
# try:
214214
# asyncio.get_running_loop()
215-
#except BaseException:
215+
# except BaseException:
216216
# asyncio.set_event_loop(asyncio.new_event_loop())
217217
self._event_pipe.send(b"")
218218
else:
@@ -482,13 +482,12 @@ def _schedule_flush(self):
482482
self._flush_pending = True
483483

484484
# add_timeout has to be handed to the io thread via event pipe
485-
#def _schedule_in_thread():
485+
# def _schedule_in_thread():
486486
# self._io_loop.call_later(self.flush_interval, self._flush)
487487

488-
#self.pub_thread.schedule(_schedule_in_thread)
488+
# self.pub_thread.schedule(_schedule_in_thread)
489489
self.pub_thread.schedule(self._flush)
490490

491-
492491
def flush(self):
493492
"""trigger actual zmq send
494493

ipykernel/ipkernel.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import sys
88
import threading
99
import typing as t
10-
from contextlib import contextmanager
11-
from functools import partial
1210

13-
import janus
1411
import comm
1512
import zmq.asyncio
1613
from IPython.core import release
@@ -232,7 +229,7 @@ def start(self):
232229
self.log.warning("debugpy_socket undefined, debugging will not be enabled")
233230
super().start()
234231
if self.debugpy_socket:
235-
#asyncio.run_coroutine_threadsafe(self.process_debugpy(), self.control_thread.loop)
232+
# asyncio.run_coroutine_threadsafe(self.process_debugpy(), self.control_thread.loop)
236233
self.control_thread.create_task(self.process_debugpy())
237234

238235
def set_parent(self, ident, parent, channel="shell"):
@@ -364,7 +361,6 @@ async def run_cell(*args, **kwargs):
364361
kwargs.update(
365362
transformed_cell=transformed_cell,
366363
preprocessing_exc_tuple=preprocessing_exc_tuple,
367-
368364
)
369365
coro = run_cell(code, **kwargs)
370366

ipykernel/kernelapp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,7 @@ def start(self):
740740
return
741741

742742
def stop(self):
743-
"""Stop the kernel, thread-safe.
744-
"""
743+
"""Stop the kernel, thread-safe."""
745744
try:
746745
self._stop_queue.sync_q.put(None)
747746
except AttributeError:

ipykernel/kernelbase.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
from ipykernel.jsonutil import json_clean
5454

55-
from .shell import ShellThread
5655
from ._version import kernel_protocol_version
56+
from .shell import ShellThread
5757

5858

5959
def DEBUG(msg):
@@ -622,12 +622,7 @@ async def execute_request(self, socket, ident, parent):
622622
kwargs.update(cell_id=cell_id)
623623

624624
reply_content = self.do_execute(
625-
code,
626-
silent,
627-
store_history,
628-
user_expressions,
629-
allow_stdin,
630-
**kwargs
625+
code, silent, store_history, user_expressions, allow_stdin, **kwargs
631626
)
632627
DEBUG(f"execute_request {parent['header'].get('shell_id')}")
633628

@@ -673,7 +668,7 @@ def do_execute(
673668
allow_stdin=False,
674669
*,
675670
cell_id=None,
676-
shell_id=None
671+
shell_id=None,
677672
):
678673
"""Execute user code. Must be overridden by subclasses."""
679674
raise NotImplementedError
@@ -873,9 +868,7 @@ async def is_complete_request(self, socket, ident, parent):
873868
if inspect.isawaitable(reply_content):
874869
reply_content = await reply_content
875870
reply_content = json_clean(reply_content)
876-
reply_msg = self.session.send(
877-
socket, "is_complete_reply", reply_content, parent, ident
878-
)
871+
reply_msg = self.session.send(socket, "is_complete_reply", reply_content, parent, ident)
879872
self.log.debug("%s", reply_msg)
880873

881874
def do_is_complete(self, code):
@@ -889,9 +882,7 @@ async def debug_request(self, socket, ident, parent):
889882
if inspect.isawaitable(reply_content):
890883
reply_content = await reply_content
891884
reply_content = json_clean(reply_content)
892-
reply_msg = self.session.send(
893-
socket, "debug_reply", reply_content, parent, ident
894-
)
885+
reply_msg = self.session.send(socket, "debug_reply", reply_content, parent, ident)
895886
self.log.debug("%s", reply_msg)
896887

897888
def get_process_metric_value(self, process, name, attribute=None):
@@ -937,9 +928,7 @@ async def usage_request(self, socket, ident, parent):
937928
reply_content["host_cpu_percent"] = cpu_percent
938929
reply_content["cpu_count"] = psutil.cpu_count(logical=True)
939930
reply_content["host_virtual_memory"] = dict(psutil.virtual_memory()._asdict())
940-
reply_msg = self.session.send(
941-
socket, "usage_reply", reply_content, parent, ident
942-
)
931+
reply_msg = self.session.send(socket, "usage_reply", reply_content, parent, ident)
943932
self.log.debug("%s", reply_msg)
944933

945934
async def do_debug_request(self, msg):
@@ -1013,9 +1002,7 @@ async def clear_request(self, socket, idents, parent): # pragma: no cover
10131002
"clear_request is deprecated in kernel_base. It is only part of IPython parallel"
10141003
)
10151004
content = self.do_clear()
1016-
self.session.send(
1017-
socket, "clear_reply", ident=idents, parent=parent, content=content
1018-
)
1005+
self.session.send(socket, "clear_reply", ident=idents, parent=parent, content=content)
10191006

10201007
def do_clear(self):
10211008
"""DEPRECATED since 4.0.3"""

ipykernel/shell.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Optional
21

32
from .athread import AThread
43

ipykernel/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _prep_msg(self, *args, **kwargs):
9292
raw_msg = self.session.msg(*args, **kwargs)
9393
msg = self.session.serialize(raw_msg)
9494
return msg
95-
#return [zmq.Message(m) for m in msg]
95+
# return [zmq.Message(m) for m in msg]
9696

9797
async def _wait_for_msg(self):
9898
while not self._reply:

ipykernel/tests/test_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def test_io_thread():
6363
pub = ctx.socket(zmq.PUB)
6464
thread = IOPubThread(pub)
6565
thread._setup_pipe_in()
66-
#msg = [thread._pipe_uuid, b"a"]
67-
#thread._handle_pipe_msg(msg)
66+
# msg = [thread._pipe_uuid, b"a"]
67+
# thread._handle_pipe_msg(msg)
6868
ctx1, pipe = thread._setup_pipe_out()
6969
pipe.close()
7070
thread._pipe_in1.close()
@@ -118,4 +118,4 @@ def test_outstream():
118118
assert stream.writable()
119119
thread.stop()
120120
thread.close()
121-
#ctx.term()
121+
# ctx.term()

0 commit comments

Comments
 (0)