In the update_plot function, I do data processing and update the column data source by cds.update(data=df). dummy_update is a print function to let me know the update was run. Now I’m having a RuntimeError: RuntimeError: _pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes. The error is at the cds.update step and I’m not sure why. Does anyone have any clue why? I did some small test, running print(“something”) inside the periodic_plot_update function, and it ran, but when involving the cds, it doesn’t.
I don’t have any specific recollection of that, but I may just be forgetting. In any case, I don’t actually know, and haven’t ever tried to do what you are doing, so I think you will just have to experiment with without_document_lock and/or wrapping changes to Bokeh objects inside another add_next_tick_callback that your async function submits.
Yes. That was what I wrote in the original code. Blocking tasks such as sleep(longtime) work, but tasks regarding document updates (data update, plot title text setting,…) don’t work with this workaround.
OK, well you still need to add another layer of callbacks. You need to put all code that changes Bokeh models in a callback of their own. Then use add_next_tick_callback on that from your async function. This is described in the docs I linked:
As with the thread example above, all actions that update document state must go through a next tick callback .
I should add: there has been proposals to remove the document locking Bokeh does and in general make it play nicer with async. But this is a big task, I mostly only have enough enough async expertise to be a little dangerous, and definitely don’t (presently) have time/bandwidth. I would be happy to provide guidance or collaborate on this with a new contributor who has deep async expertise, and wants to dive into a non-trivial problem, though.