Skip to content

Commit 15c9635

Browse files
meeseeksmachinedleenZsailer
authored
Backport PR #836: Call "/api/shutdown" instead of "/" (#837)
Co-authored-by: David Leen <[email protected]> Co-authored-by: Zachary Sailer <[email protected]>
1 parent 0658988 commit 15c9635

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
@@ -501,10 +501,29 @@ def shutdown_server(server_info, timeout=5, log=None):
501501
url = server_info["url"]
502502
pid = server_info["pid"]
503503

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

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

0 commit comments

Comments
 (0)