Skip to content

Commit

Permalink
Respect write-locks in synchronous Websocket events (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 20, 2020
1 parent 46c3679 commit 6c951db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def unlocked():
events = []
for conn in connections:
socket = conn._socket
if hasattr(socket, 'write_lock') and socket.write_lock._block._value == 0:
state._locks.add(socket)
locked = socket in state._locks
for event in curdoc._held_events:
if (isinstance(event, ModelChangedEvent) and event not in old_events
and hasattr(socket, 'write_message')):
and hasattr(socket, 'write_message') and not locked):
msg = conn.protocol.create('PATCH-DOC', [event])
WebSocketHandler.write_message(socket, msg.header_json)
WebSocketHandler.write_message(socket, msg.metadata_json)
Expand Down
5 changes: 5 additions & 0 deletions panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import threading

from weakref import WeakSet

import param

from bokeh.document import Document
Expand Down Expand Up @@ -49,6 +51,9 @@ class _state(param.Parameterized):
# Jupyter display handles
_handles = {}

# Stores a set of locked Websockets, reset after every change event
_locks = WeakSet()

def __repr__(self):
server_info = []
for server, panel, docs in self._servers.values():
Expand Down
1 change: 1 addition & 0 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ def _comm_change(self, msg, ref=None):
self._changing = {}

def _server_change(self, doc, ref, attr, old, new):
state._locks.clear()
self._events.update({attr: new})
if not self._processing:
self._processing = True
Expand Down

0 comments on commit 6c951db

Please sign in to comment.