Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 3b838f7

Browse files
committed
Rename infer_jupyter_config to infer_jupyter_proxy_config and raise exception if
config can not be inferred
1 parent d66a1d8 commit 3b838f7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

jupyter_dash/comms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _jupyter_comm_response_received():
3030
return bool(_jupyter_config)
3131

3232

33-
def _request_jupyter_config(timeout=1):
33+
def _request_jupyter_proxy_config(timeout=2):
3434
# Heavily inspired by implementation of CaptureExecution in the
3535
if _dash_comm.kernel is None:
3636
# Not in jupyter server setting
@@ -59,7 +59,10 @@ def capture_event(stream, ident, parent):
5959
while True:
6060
if (time.time() - t0) > timeout:
6161
# give up
62-
break
62+
raise EnvironmentError(
63+
"Unable to communicate with the jupyter_dash notebook or JupyterLab \n"
64+
"extension required to infer proxy configuration."
65+
)
6366
if _jupyter_comm_response_received():
6467
break
6568

jupyter_dash/jupyter_app.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88

99

1010
from IPython.display import IFrame, display
11-
from .comms import _dash_comm, _jupyter_config, _request_jupyter_config
11+
from .comms import _dash_comm, _jupyter_config, _request_jupyter_proxy_config
1212

1313

1414
class JupyterDash(dash.Dash):
1515
@classmethod
16-
def infer_jupyter_config(cls):
17-
_request_jupyter_config()
16+
def infer_jupyter_proxy_config(cls):
17+
try:
18+
import jupyter_server_proxy
19+
except Exception:
20+
raise ImportError(
21+
"The infer_jupyter_proxy_config function requires the"
22+
"jupyter_server_proxy Python package"
23+
)
24+
_request_jupyter_proxy_config()
1825

1926
def __init__(self, server_url=None, **kwargs):
2027

0 commit comments

Comments
 (0)