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

Fix event dispatch #3231

Merged
merged 2 commits into from
Mar 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _thread_id(self, thread_id):
def _unblocked(self, doc):
thread = threading.current_thread()
thread_id = thread.ident if thread else None
return doc is self.curdoc and self._thread_id == thread_id
return doc is self.curdoc and self._thread_id in (thread_id, None)

@param.depends('busy', watch=True)
def _update_busy(self):
Expand Down
21 changes: 10 additions & 11 deletions panel/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
from bokeh.models import LayoutDOM
from bokeh.model import DataModel
from param.parameterized import ParameterizedMetaclass, Watcher
from tornado import gen

from .io.model import hold
from .io.notebook import push
from .io.server import unlocked
from .io.state import state
from .io.state import set_curdoc, state
from .models.reactive_html import (
ReactiveHTML as _BkReactiveHTML, ReactiveHTMLParser
)
Expand Down Expand Up @@ -278,19 +277,19 @@ def _process_events(self, events):
with edit_readonly(state):
state.busy = busy

@gen.coroutine
def _change_coroutine(self, doc=None):
async def _change_coroutine(self, doc=None):
if state._thread_pool:
state._thread_pool.submit(self._change_event, doc)
else:
self._change_event(doc)
with set_curdoc(doc):
self._change_event(doc)

@gen.coroutine
def _event_coroutine(self, event):
async def _event_coroutine(self, event, doc):
if state._thread_pool:
state._thread_pool.submit(self._process_event, event)
else:
self._process_event(event)
with set_curdoc(doc):
self._process_event(event)

def _change_event(self, doc=None):
try:
Expand Down Expand Up @@ -325,12 +324,12 @@ def _comm_event(self, event):
self._process_event(event)

def _server_event(self, doc, event):
if doc.session_context:
if doc.session_context and not state._unblocked(doc):
doc.add_next_tick_callback(
partial(self._event_coroutine, event)
partial(self._event_coroutine, event, doc)
)
else:
self._process_event(event)
self._comm_event(event)

def _server_change(self, doc, ref, subpath, attr, old, new):
if subpath:
Expand Down
6 changes: 3 additions & 3 deletions panel/tests/pane/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_load_from_stringio():

def test_loading_a_image_from_url():
"""Tests the loading of a image from a url"""
url = 'https://file-examples-com.github.io/uploads/2017/10/file_example_PNG_500kB.png'
url = 'https://raw.githubusercontent.com/holoviz/panel/master/doc/_static/logo.png'

image_pane = PNG(url)
image_data = image_pane._data()
Expand All @@ -114,7 +114,7 @@ def test_loading_a_image_from_pathlib():

def test_image_alt_text(document, comm):
"""Tests the loading of a image from a url"""
url = 'https://file-examples-com.github.io/uploads/2017/10/file_example_PNG_500kB.png'
url = 'https://raw.githubusercontent.com/holoviz/panel/master/doc/_static/logo.png'

image_pane = PNG(url, embed=False, alt_text="Some alt text")
model = image_pane.get_root(document, comm)
Expand All @@ -124,7 +124,7 @@ def test_image_alt_text(document, comm):

def test_image_link_url(document, comm):
"""Tests the loading of a image from a url"""
url = 'https://file-examples-com.github.io/uploads/2017/10/file_example_PNG_500kB.png'
url = 'https://raw.githubusercontent.com/holoviz/panel/master/doc/_static/logo.png'

image_pane = PNG(url, embed=False, link_url="http://anaconda.org")
model = image_pane.get_root(document, comm)
Expand Down