Skip to content

Commit 16807bf

Browse files
committed
require psutil on all platforms
now needed for cleanup on all platforms, as well as usage_requests
1 parent 511e8e0 commit 16807bf

File tree

3 files changed

+3
-27
lines changed

3 files changed

+3
-27
lines changed

ipykernel/kernelbase.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
SIGKILL = "windown-SIGKILL-sentinel"
2525

2626

27-
try:
28-
import psutil
29-
except ImportError:
30-
psutil = None
3127

3228

3329
try:
@@ -37,6 +33,7 @@
3733
# jupyter_client < 5, use local now()
3834
now = datetime.now
3935

36+
import psutil
4037
import zmq
4138
from IPython.core.error import StdinNotImplementedError
4239
from jupyter_client.session import Session
@@ -898,8 +895,6 @@ async def usage_request(self, stream, ident, parent):
898895
reply_content = {
899896
'hostname': socket.gethostname()
900897
}
901-
if psutil is None:
902-
return reply_content
903898
current_process = psutil.Process()
904899
all_processes = [current_process] + current_process.children(recursive=True)
905900
process_metric_value = self.get_process_metric_value
@@ -1144,10 +1139,6 @@ def _signal_children(self, signum):
11441139
Like `killpg`, but does not include the current process
11451140
(or possible parents).
11461141
"""
1147-
if psutil is None:
1148-
self.log.info("Need psutil to signal children")
1149-
return
1150-
11511142
for p in self._process_children():
11521143
self.log.debug(f"Sending {Signals(signum)!r} to subprocess {p}")
11531144
try:
@@ -1167,8 +1158,6 @@ def _process_children(self):
11671158
- including parents and self with killpg
11681159
- including all children that may have forked-off a new group
11691160
"""
1170-
if psutil is None:
1171-
return []
11721161
kernel_process = psutil.Process()
11731162
all_children = kernel_process.children(recursive=True)
11741163
if os.name == "nt":
@@ -1186,11 +1175,6 @@ def _process_children(self):
11861175
return process_group_children
11871176

11881177
async def _progressively_terminate_all_children(self):
1189-
if psutil is None:
1190-
# we need psutil to safely clean up children
1191-
self.log.info("Please install psutil for a cleaner subprocess shutdown.")
1192-
return
1193-
11941178
sleeps = (0.01, 0.03, 0.1, 0.3, 1, 3, 10)
11951179
if not self._process_children():
11961180
self.log.debug("Kernel has no children.")

ipykernel/tests/test_kernel.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
from tempfile import TemporaryDirectory
1515

1616
from flaky import flaky
17+
import psutil
1718
import pytest
1819

19-
try:
20-
import psutil
21-
except ImportError:
22-
psutil = None
23-
2420
import IPython
2521
from IPython.paths import locate_profile
2622

@@ -535,10 +531,6 @@ def _start_children():
535531
platform.python_implementation() == "PyPy",
536532
reason="does not work on PyPy",
537533
)
538-
@pytest.mark.skipif(
539-
psutil is None,
540-
reason="requires psutil",
541-
)
542534
def test_shutdown_subprocesses():
543535
"""Kernel exits after polite shutdown_request"""
544536
with new_kernel() as kc:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run(self):
6868
'tornado>=4.2,<7.0',
6969
'matplotlib-inline>=0.1.0,<0.2.0',
7070
'appnope;platform_system=="Darwin"',
71-
'psutil;platform_system=="Windows"',
71+
'psutil',
7272
'nest_asyncio',
7373
],
7474
extras_require={

0 commit comments

Comments
 (0)