Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 6a653c0

Browse files
committed
Propagate start errors.
1 parent b6dad26 commit 6a653c0

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

jupyter_dash/jupyter_app.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import os
33
import requests
44
import flask.cli
5+
from IPython.core.display import HTML
56
from retrying import retry
67
import io
78
import re
89
import sys
910
import inspect
1011
import traceback
1112
import warnings
13+
import queue
1214

1315
from IPython import get_ipython
1416
from 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

Comments
 (0)