mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Merge pull request #32 from rprimet/handle_transient
Handle transient errors
This commit is contained in:
@@ -2,6 +2,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import tljh.systemd as systemd
|
import tljh.systemd as systemd
|
||||||
import tljh.conda as conda
|
import tljh.conda as conda
|
||||||
|
from urllib.error import HTTPError
|
||||||
from urllib.request import urlopen, URLError
|
from urllib.request import urlopen, URLError
|
||||||
from tljh import user
|
from tljh import user
|
||||||
import secrets
|
import secrets
|
||||||
@@ -139,11 +140,18 @@ def ensure_jupyterhub_running(times=4):
|
|||||||
Loops given number of times, waiting a second each.
|
Loops given number of times, waiting a second each.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for i in range(4):
|
for i in range(times):
|
||||||
try:
|
try:
|
||||||
print('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times))
|
print('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times))
|
||||||
urlopen('http://127.0.0.1')
|
urlopen('http://127.0.0.1')
|
||||||
return
|
return
|
||||||
|
except HTTPError as h:
|
||||||
|
if h.code in [404, 503]:
|
||||||
|
# May be transient
|
||||||
|
time.sleep(1)
|
||||||
|
continue
|
||||||
|
# Everything else should immediately abort
|
||||||
|
raise
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
if isinstance(e.reason, ConnectionRefusedError):
|
if isinstance(e.reason, ConnectionRefusedError):
|
||||||
# Hub isn't up yet, sleep & loop
|
# Hub isn't up yet, sleep & loop
|
||||||
|
|||||||
Reference in New Issue
Block a user