2
2
import os
3
3
import requests
4
4
import flask .cli
5
+ from IPython .core .display import HTML
5
6
from retrying import retry
6
7
import io
7
8
import re
8
9
import sys
9
10
import inspect
10
11
import traceback
11
12
import warnings
13
+ import queue
12
14
13
15
from IPython import get_ipython
14
16
from IPython .display import IFrame , display
@@ -298,6 +300,8 @@ def run(
298
300
except ImportError :
299
301
pass
300
302
303
+ err_q = queue .Queue ()
304
+
301
305
@retry (
302
306
stop_max_attempt_number = 15 ,
303
307
wait_exponential_multiplier = 100 ,
@@ -308,6 +312,8 @@ def run():
308
312
super_run_server (** kwargs )
309
313
except SystemExit :
310
314
pass
315
+ except Exception as error :
316
+ err_q .put (error )
311
317
312
318
thread = StoppableThread (target = run )
313
319
thread .setDaemon (True )
@@ -327,7 +333,17 @@ def run():
327
333
wait_exponential_max = 1000
328
334
)
329
335
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
+
331
347
if res != "Alive" :
332
348
url = "http://{host}:{port}" .format (
333
349
host = host , port = port , token = JupyterDash ._token
@@ -339,12 +355,19 @@ def wait_for_app():
339
355
)
340
356
)
341
357
342
- wait_for_app ()
358
+ try :
359
+ wait_for_app ()
343
360
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
348
371
349
372
def _display_in_colab (self , dashboard_url , port , mode , width , height ):
350
373
from google .colab import output
0 commit comments