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

Respect write-locks in synchronous Websocket events #1170

Merged
merged 2 commits into from
Mar 20, 2020
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 20, 2020

As described in #1148 we override the bokeh Websocket handlers asynchronous locking mechanisms to allow synchronous functions to trigger updates on the frontend immediately instead of blocking until they finish, e.g.:

import panel as pn
import time

button = pn.widgets.Button(name='Run')
progress = pn.widgets.Progress(value=0)

def update_progress(event):
    for i in range(100):
        time.sleep(0.01)
        progress.value = i

button.on_click(update_progress)

pn.Row(button, progress).show()

If we didn't do this, this example wouldn't update the progress bar until the callback finishes. However in implementing this we are not respecting the Websocket handlers write lock. This PR ensures checks whether a write lock is enabled and if so locks the synchronous events out. This ensures most computations where updates aren't triggered in very quick succession can synchronously trigger events but may result in unexpected behavior where a callback suddenly locks in the middle. However once the callback finishes it'll all be made consistent so I think this is a worthwhile tradeoff until we handle async callbacks correctly.

Fixes #1148

@codecov
Copy link

codecov bot commented Mar 20, 2020

Codecov Report

Merging #1170 into master will decrease coverage by 0.01%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1170      +/-   ##
==========================================
- Coverage   87.81%   87.79%   -0.02%     
==========================================
  Files         105      105              
  Lines       12592    12598       +6     
==========================================
+ Hits        11058    11061       +3     
- Misses       1534     1537       +3     
Impacted Files Coverage Δ
panel/io/server.py 40.00% <0.00%> (-0.91%) ⬇️
panel/io/state.py 90.19% <100.00%> (+0.40%) ⬆️
panel/viewable.py 82.21% <100.00%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46c3679...b7cf380. Read the comment docs.

panel/io/server.py Outdated Show resolved Hide resolved
@philippjfr philippjfr merged commit 6c951db into master Mar 20, 2020
@mattpap
Copy link
Collaborator

mattpap commented Mar 20, 2020

@philippjfr, what's your policy on branch removal? I see that most (all?) are being kept after mege.

@philippjfr
Copy link
Member Author

@philippjfr, what's your policy on branch removal? I see that most (all?) are being kept after mege.

There's an option to do this automatically right? Right now I manually delete them once in a while.

@philippjfr philippjfr deleted the enforce_ws_lock branch March 20, 2020 14:49
@philippjfr
Copy link
Member Author

Thanks, enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bokeh] Closing connection: No msgid in header
2 participants