Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for pyodide handling #3444

Merged
merged 2 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
load_notebook, push, push_notebook
)

if '_pyodide' in sys.modules:
if state._is_pyodide:
from .pyodide import serve
else:
from .server import serve # noqa
Expand Down
5 changes: 2 additions & 3 deletions panel/io/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import inspect
import logging
import time
import sys

import param

Expand Down Expand Up @@ -165,7 +164,7 @@ def start(self):
finally:
self._updating = False
self._start_time = time.time()
if '_pyodide' in sys.modules:
if state._is_pyodide:
event_loop = asyncio.get_running_loop()
task = asyncio.create_task(
self._async_repeat(self._periodic_callback)
Expand Down Expand Up @@ -195,7 +194,7 @@ def stop(self):
self._updating = False
self._counter = 0
self._timeout = None
if '_pyodide' in sys.modules:
if state._is_pyodide:
self._cb.cancel()
elif self._doc:
if self._doc._session_context:
Expand Down
6 changes: 4 additions & 2 deletions panel/io/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from bokeh import __version__
from bokeh.document import Document
from bokeh.embed.util import standalone_docs_json
from bokeh.embed.util import standalone_docs_json_and_render_items
from bokeh.protocol.messages.patch_doc import process_document_events

from . import resources
Expand Down Expand Up @@ -40,7 +40,9 @@ def _doc_json(model, target):
doc = Document()
model.server_doc(doc=doc)
model = doc.roots[0]
docs_json = standalone_docs_json([model])
docs_json, _ = standalone_docs_json_and_render_items(
[model], suppress_callback_warning=True
)

doc_json = list(docs_json.values())[0]
root_id = doc_json['roots']['root_ids'][0]
Expand Down
6 changes: 5 additions & 1 deletion panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ def __repr__(self):

@property
def _ioloop(self):
if 'pyodide' in sys.modules:
if state._is_pyodide:
return asyncio.get_running_loop()
else:
from tornado.ioloop import IOLoop
return IOLoop.current()

@property
def _is_pyodide(self):
return '_pyodide' in sys.modules

@property
def _thread_id(self):
return self._thread_id_.get(self.curdoc) if self.curdoc else None
Expand Down