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

Commit

Permalink
Merge pull request #86 from plotly/fix-parent
Browse files Browse the repository at this point in the history
fix infer_jupyter_proxy_config again for new jupyterlab
  • Loading branch information
alexcjohnson authored Apr 1, 2022
2 parents da91751 + 9c6e668 commit 80fb8bb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jupyter_dash/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@

_dash_comm = Comm(target_name='jupyter_dash')

_caller = {}


def _send_jupyter_config_comm_request():
# If running in an ipython kernel,
# request that the front end extension send us the notebook server base URL
if IPython.get_ipython() is not None:
if _dash_comm.kernel is not None:
_caller["parent"] = _dash_comm.kernel.get_parent()
_dash_comm.send({
'type': 'base_url_request'
})


@_dash_comm.on_msg
def _receive_message(msg):
prev_parent = _caller.get("parent")
if prev_parent and prev_parent != _dash_comm.kernel.get_parent():
_dash_comm.kernel.set_parent([prev_parent["header"]["session"]], prev_parent)
del _caller["parent"]

msg_data = msg.get('content').get('data')
msg_type = msg_data.get('type', None)
if msg_type == 'base_url_response':
Expand Down Expand Up @@ -69,8 +77,8 @@ def capture_event(stream, ident, parent):
break

if asyncio.iscoroutinefunction(kernel.do_one_iteration):
nest_asyncio.apply()
loop = asyncio.get_event_loop()
nest_asyncio.apply(loop)
loop.run_until_complete(kernel.do_one_iteration())
else:
kernel.do_one_iteration()
Expand Down

0 comments on commit 80fb8bb

Please sign in to comment.