22import os
33import requests
44import flask .cli
5+ from IPython .core .display import HTML
56from retrying import retry
67import io
78import re
89import sys
910import inspect
1011import traceback
1112import warnings
13+ import queue
1214
1315from IPython import get_ipython
1416from IPython .display import IFrame , display
@@ -298,6 +300,8 @@ def run(
298300 except ImportError :
299301 pass
300302
303+ err_q = queue .Queue ()
304+
301305 @retry (
302306 stop_max_attempt_number = 15 ,
303307 wait_exponential_multiplier = 100 ,
@@ -308,6 +312,8 @@ def run():
308312 super_run_server (** kwargs )
309313 except SystemExit :
310314 pass
315+ except Exception as error :
316+ err_q .put (error )
311317
312318 thread = StoppableThread (target = run )
313319 thread .setDaemon (True )
@@ -327,7 +333,17 @@ def run():
327333 wait_exponential_max = 1000
328334 )
329335 def wait_for_app ():
330- res = requests .get (alive_url ).content .decode ()
336+ try :
337+ err = err_q .get_nowait ()
338+ if err :
339+ raise err
340+ except queue .Empty :
341+ pass
342+ req = requests .get (alive_url )
343+ res = req .content .decode ()
344+ if req .status_code == 500 :
345+ raise Exception (res )
346+
331347 if res != "Alive" :
332348 url = "http://{host}:{port}" .format (
333349 host = host , port = port , token = JupyterDash ._token
@@ -339,12 +355,19 @@ def wait_for_app():
339355 )
340356 )
341357
342- wait_for_app ()
358+ try :
359+ wait_for_app ()
343360
344- if JupyterDash ._in_colab :
345- self ._display_in_colab (dashboard_url , port , mode , width , height )
346- else :
347- self ._display_in_jupyter (dashboard_url , port , mode , width , height )
361+ if JupyterDash ._in_colab :
362+ self ._display_in_colab (dashboard_url , port , mode , width , height )
363+ else :
364+ self ._display_in_jupyter (dashboard_url , port , mode , width , height )
365+ except Exception as final_error :
366+ msg = final_error .args [0 ]
367+ if msg .startswith ('<!' ):
368+ display (HTML (msg ))
369+ else :
370+ raise final_error
348371
349372 def _display_in_colab (self , dashboard_url , port , mode , width , height ):
350373 from google .colab import output
0 commit comments