Skip to content

Commit 55974d3

Browse files
author
lindakladivova
committed
applying relevant github-advanced-security suggestions
1 parent 817795e commit 55974d3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

gui/wxpython/jupyter_notebook/panel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
@author Linda Karlovska <linda.karlovska seznam.cz>
1515
"""
1616

17-
import wx
1817
from pathlib import Path
1918

20-
from .notebook import JupyterAuiNotebook
21-
from .toolbars import JupyterToolbar
19+
import wx
20+
2221
from main_window.page import MainPageBase
2322
from grass.workflows.directory import JupyterDirectoryManager
2423
from grass.workflows.server import JupyterServerInstance, JupyterServerRegistry
2524

25+
from .notebook import JupyterAuiNotebook
26+
from .toolbars import JupyterToolbar
27+
2628

2729
class JupyterPanel(wx.Panel, MainPageBase):
2830
def __init__(

python/grass/workflows/server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import atexit
4949
import signal
5050
import sys
51+
import shutil
5152

5253

5354
class JupyterServerInstance:
@@ -112,7 +113,7 @@ def find_free_port():
112113
:return: A free port number (int).
113114
"""
114115
with socket.socket() as sock:
115-
sock.bind(("", 0))
116+
sock.bind(("127.0.0.1", 0))
116117
return sock.getsockname()[1]
117118

118119
def is_server_running(self, retries=10, delay=0.2):
@@ -183,6 +184,9 @@ def stop_server(self):
183184

184185
# Check if the process with the given PID is a Jupyter server
185186
try:
187+
ps_cmd = shutil.which("ps")
188+
if not ps_cmd:
189+
raise RuntimeError(_("Unable to find 'ps' command in PATH."))
186190
proc_name = (
187191
subprocess.check_output(["ps", "-p", str(self.pid), "-o", "args="])
188192
.decode()
@@ -194,12 +198,17 @@ def stop_server(self):
194198
"Process with PID {} is not a Jupyter server: found '{}'."
195199
).format(self.pid, proc_name)
196200
)
197-
except subprocess.CalledProcessError:
198-
raise RuntimeError(_("No process found with PID {}.").format(self.pid))
201+
except subprocess.CalledProcessError as e:
202+
raise RuntimeError(
203+
_("No process found with PID {}.").format(self.pid)
204+
) from e
199205

200206
# Attempt to terminate the server process
201207
if self.is_server_running(self.port):
202208
try:
209+
kill_cmd = shutil.which("kill")
210+
if not kill_cmd:
211+
raise RuntimeError(_("Unable to find 'kill' command in PATH."))
203212
subprocess.check_call(["kill", str(self.pid)])
204213
except subprocess.CalledProcessError as e:
205214
raise RuntimeError(

0 commit comments

Comments
 (0)