Skip to content

Commit 144d842

Browse files
committed
try some more shutdown tricks
1 parent 2b564aa commit 144d842

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

atest/acceptance/01_server/00_basic.robot

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ Start three servers
2626
Should Contain ${log1} The Jupyter Notebook is running msg=Log should contain expected status message
2727
${log2} = Get Process Result ${nb2} stderr=${True}
2828
Should Contain ${log2} The Jupyter Notebook is running msg=Log should contain expected status message
29-
${log3} = Get Process Result ${nb3} stderr=${True}
30-
Should Contain ${log2} The Jupyter Notebook is running msg=Log should contain expected status message
3129
${terminated} = Terminate All Jupyter Servers
3230
Should be equal as integers ${terminated} 0 msg=No servers should have been terminated
3331

atest/acceptance/__init__.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*** Settings ***
22
Suite Teardown Clean Up Everything
3-
Test Timeout 5m
43
Library JupyterLibrary
54
Library Process
65

src/JupyterLibrary/keywords/server.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def start_new_jupyter_server(
6161
args = args or self.build_jupyter_server_arguments(port, base_url, token)
6262

6363
handle = plib.start_process(command, *args, **config)
64-
BuiltIn().sleep("5s")
65-
plib.process_should_be_running(handle)
6664

6765
self._handles += [handle]
6866
self._tmpdirs[handle] = tmpdir
@@ -81,9 +79,9 @@ def build_jupyter_server_arguments(self, port, base_url, token):
8179
"notebook",
8280
"--no-browser",
8381
"--debug",
84-
f"--port={port}",
85-
f"--NotebookApp.token='{token}'",
86-
f"--NotebookApp.base_url='{base_url}'",
82+
"--port={}".format(port),
83+
"--NotebookApp.token='{}'".format(token),
84+
"--NotebookApp.base_url='{}'".format(base_url),
8785
]
8886

8987
@keyword
@@ -169,22 +167,40 @@ def terminate_all_jupyter_servers(self):
169167
""" Close all Jupyter servers started by JupyterLibrary
170168
"""
171169
plib = BuiltIn().get_library_instance("Process")
170+
171+
self.wait_for_jupyter_server_to_be_ready()
172+
172173
terminated = 0
174+
shutdown = 0
173175
for nbh in self._handles:
174-
plib.terminate_process(nbh, kill=True)
176+
url = self.get_jupyter_server_url(nbh)
177+
token = self.get_jupyter_server_token(nbh)
175178
try:
176-
shutil.rmtree(self._tmpdirs[nbh])
177-
except Exception:
178-
BuiltIn().log(f"Failed to delete {self._tmpdirs[nbh]}")
179-
BuiltIn().sleep("5s")
180-
try:
181-
shutil.rmtree(self._tmpdirs[nbh])
182-
except Exception:
183-
BuiltIn().log(f"Giving up {self._tmpdirs[nbh]}")
179+
urlopen("{}api/shutdown?token={}".format(url, token), data=[])
180+
shutdown += 1
181+
except Exception as err:
182+
BuiltIn().log(err)
184183

185-
terminated += 1
184+
if shutdown:
185+
for nbh in self._handles:
186+
try:
187+
plib.terminate_process(nbh, kill=True)
188+
terminated += 1
189+
except Exception as err:
190+
BuiltIn().log(err)
191+
192+
# give processes a mo to shutdown
193+
if terminated or shutdown:
194+
BuiltIn().sleep("5s")
195+
for nbh in self._handles:
196+
shutil.rmtree(self._tmpdirs[nbh])
186197

187198
self._handles = []
199+
self._tmpdirs = {}
200+
self._notebook_dirs = {}
201+
self._ports = {}
202+
self._base_urls = {}
203+
self._tokens = {}
188204

189205
return terminated
190206

0 commit comments

Comments
 (0)