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

_pending_writes should be non-None when we have a document lock #344

Closed
xavArtley opened this issue Mar 29, 2019 · 12 comments
Closed

_pending_writes should be non-None when we have a document lock #344

xavArtley opened this issue Mar 29, 2019 · 12 comments

Comments

@xavArtley
Copy link
Collaborator

import panel as pn
import tkinter as tk
from threading import Thread
from panel.io import get_server
from functools import partial

slider = pn.widgets.FloatSlider()

import asyncio


def get_server_in_thread(**kwargs):
    asyncio.set_event_loop(asyncio.new_event_loop())
    get_server(**kwargs)

class Display():

    def __init__(self):
        Thread(target=partial(get_server_in_thread,panel=slider,start=True,show=True,port=5010)).start()
        self.root = tk.Tk()
        self.slider = tk.Scale(self.root, from_=0., to=1., resolution=0.1,
                               orient=tk.HORIZONTAL, command=self.on_slider_change)
        self.slider.pack()
        self.root.mainloop()


    def on_slider_change(self, event):
        slider.value = float(event)

display = Display()

ezgif com-video-to-gif (2)

@xavArtley
Copy link
Collaborator Author

May be a windows related issue

@philippjfr
Copy link
Member

Thanks, I'll try to set this up on my windows machine.

@xavArtley
Copy link
Collaborator Author

This is call stacks, left when there is error, right when the update succeed
error
It seems like the callback is called from the wrong thread (main)

@philippjfr
Copy link
Member

That's odd, I'd expect this to schedule an event on the IO loop which should then be run on the thread:

    def on_slider_change(self, event):
        slider.value = float(event)

What I think is happening is that for whatever reason pn.state.curdoc is defined, which causes it to skip the scheduling. Could you insert some print statements panel.io.state.curdoc and see what is setting the curdoc?

@philippjfr
Copy link
Member

When I try this locally (where it is working) pn.state.curdoc is always defined when the JS slider is dragged and is None when the Tk slider is dragged, which is what I'd expect.

@xavArtley
Copy link
Collaborator Author

Capture

@xavArtley
Copy link
Collaborator Author

Mine is always state00002

@philippjfr
Copy link
Member

philippjfr commented Mar 29, 2019

Not looking for the value of state itself, it's state.curdoc I'm interested in. It should be none whenever the tk slider is dragged.

@xavArtley
Copy link
Collaborator Author

xavArtley commented Mar 29, 2019

none when tk slider and document when bokeh one
image

@philippjfr
Copy link
Member

That's bizarre, I don't know how the error can occur if it is None. Here is the relevant code, if it is None it should go into the else branch but it seems to be going into the first branch:

if comm or doc is state.curdoc:
    self._update_model(events, msg, root, model, doc, comm)
    if comm and 'embedded' not in root.tags:
        push(doc, comm)
else:
    cb = partial(self._update_model, events, msg, root, model, doc, comm)
    doc.add_next_tick_callback(cb)

@philippjfr
Copy link
Member

What I can try to do is record the thread id, and if we're on the wrong thread it would force it to go down the else branch.

@xavArtley
Copy link
Collaborator Author

Indeed if I force using the else part there is no problem

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

No branches or pull requests

2 participants