Skip to content

Commit 152c490

Browse files
committed
#786: updates to shutdown
1 parent 57f3721 commit 152c490

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

dtale/app.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
)
5151
from dtale.views import DtaleData, head_endpoint, is_up, kill, startup
5252

53-
if PY3:
54-
import _thread
55-
else:
56-
import thread as _thread
57-
5853
logger = logging.getLogger(__name__)
5954

6055
USE_NGROK = False
@@ -423,8 +418,12 @@ def shutdown_server():
423418
logger.info("Executing shutdown...")
424419
func = request.environ.get("werkzeug.server.shutdown")
425420
if func is None:
426-
raise RuntimeError("Not running with the Werkzeug Server")
427-
func()
421+
logger.info("Not running with the Werkzeug Server, exiting using os._exit")
422+
import os
423+
424+
os._exit(os.EX_OK)
425+
else:
426+
func()
428427
global_state.cleanup()
429428
ACTIVE_PORT = None
430429
ACTIVE_HOST = None
@@ -830,7 +829,10 @@ def _start():
830829
if is_active:
831830
_start()
832831
else:
833-
_thread.start_new_thread(_start, ())
832+
import multiprocessing
833+
834+
p = multiprocessing.Process(target=_start, args=())
835+
p.start()
834836

835837
if final_options["notebook"]:
836838
instance.notebook()

dtale/views.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ def kill(base):
192192
This function fires a request to this instance's 'shutdown' route to kill it
193193
194194
"""
195-
requests.get(build_shutdown_url(base))
195+
try:
196+
requests.get(build_shutdown_url(base))
197+
except BaseException:
198+
logger.info("Shutdown complete")
196199

197200

198201
def is_up(base):

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run_tests(self):
8383
install_requires=read_file("requirements.txt"),
8484
extras_require={
8585
"arctic": ["arctic <= 1.79.4"],
86-
"arcticdb": ["arcticdb"],
86+
"arcticdb": ["arcticdb != 1.6.1"],
8787
"dash-bio": [
8888
"ParmEd==3.4.3; python_version == '3.6'",
8989
"dash-bio; python_version > '3.0'",

tests/dtale/test_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def run(self, *args, **kwargs):
320320
ignore_duplicate=True,
321321
)
322322

323-
with mock.patch("dtale.app._thread.start_new_thread", mock.Mock()) as mock_thread:
323+
with mock.patch("multiprocessing.Process", mock.Mock()) as mock_thread:
324324
show(data=test_data, subprocess=True, ignore_duplicate=True)
325325
mock_thread.assert_called()
326326

tests/dtale/test_views.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,25 @@ def import_mock(name, *args, **kwargs):
435435

436436
@pytest.mark.unit
437437
def test_shutdown(unittest):
438+
import werkzeug
439+
438440
with app.test_client() as c:
439441
try:
440-
c.get("/shutdown")
442+
with ExitStack() as stack:
443+
mock_os = stack.enter_context(mock.patch("os._exit", mock.Mock()))
444+
resp = c.get("/shutdown").data
445+
assert "Server shutting down..." in str(resp)
446+
mock_os.assert_called()
441447
unittest.fail()
442448
except: # noqa
443449
pass
444-
mock_shutdown = mock.Mock()
445-
resp = c.get(
446-
"/shutdown", environ_base={"werkzeug.server.shutdown": mock_shutdown}
447-
).data
448-
assert "Server shutting down..." in str(resp)
449-
mock_shutdown.assert_called()
450+
if parse_version(werkzeug.__version__) < parse_version("2.1.0"):
451+
mock_shutdown = mock.Mock()
452+
resp = c.get(
453+
"/shutdown", environ_base={"werkzeug.server.shutdown": mock_shutdown}
454+
).data
455+
assert "Server shutting down..." in str(resp)
456+
mock_shutdown.assert_called()
450457

451458

452459
@pytest.mark.unit

0 commit comments

Comments
 (0)