Skip to content

Commit

Permalink
Improvements for pyodide handling (#3444)
Browse files Browse the repository at this point in the history
* Improvements for pyodide handling

* Fix flakes
  • Loading branch information
philippjfr committed Apr 23, 2022
1 parent 2ba0b94 commit 0cc5ab9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
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

0 comments on commit 0cc5ab9

Please sign in to comment.