Skip to content

Commit 05834ea

Browse files
authored
Call "/api/shutdown" instead of "/" (#836)
1 parent d7307d0 commit 05834ea

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

jupyter_server/serverapp.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,29 @@ def shutdown_server(server_info, timeout=5, log=None):
508508
url = server_info["url"]
509509
pid = server_info["pid"]
510510

511-
if log:
512-
log.debug("POST request to %sapi/shutdown", url)
511+
try:
512+
shutdown_url = urljoin(url, "api/shutdown")
513+
if log:
514+
log.debug("POST request to %s", shutdown_url)
515+
fetch(
516+
shutdown_url,
517+
method="POST",
518+
body=b"",
519+
headers={"Authorization": "token " + server_info["token"]},
520+
)
521+
except Exception as ex:
522+
if not str(ex) == "Unknown URL scheme.":
523+
raise ex
524+
if log:
525+
log.debug("Was not a HTTP scheme. Treating as socket instead.")
526+
log.debug("POST request to %s", url)
527+
fetch(
528+
url,
529+
method="POST",
530+
body=b"",
531+
headers={"Authorization": "token " + server_info["token"]},
532+
)
513533

514-
fetch(url, method="POST", body=b"", headers={"Authorization": "token " + server_info["token"]})
515534
# Poll to see if it shut down.
516535
for _ in range(timeout * 10):
517536
if not check_pid(pid):

0 commit comments

Comments
 (0)