Question about document lock and _pending_writes error


I am writing an application (bokeh server application) showing several lines from a pandas dataset (read from CSV files).
My problem is that in some cases, when I load the application I got the following error message about Document lock while updating some glyph properties (visible or data source) :
error: RuntimeError(’_pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes’)

self.lines[line] = dict(self.dataSource[line].data)

The document is updated with a callback on some Select widget.

An initial update is performed from the main program.

As I have read from previous posts, this probleme can happen is the document is updated from a thread (not the case).

Sorry not to be able to post a minimal reproducible example now, I am trying to eliminate some part of the code to make it clearer.

As the application is full of buttons that trigger updates of the document or the glyph, I would like to know how it is possible to check that the document is locked or if there is a pending operation on it ?

Also, is it normal (for test, maybe stupid question) that if I try to connect to the same application from several tabs of a browser I also get a document lock error ? Is it because I have functions taking too much time ?

With a minimal example of a figure I have no problem.

My version is : Bokeh version : 2.2.3 / Debian 10.2



After more investigation and research on the support, I modified the structure of the code.
Originally : : class graphic(inheriting from results class) : class results

as the imported modules might be shared between sessions, I put all the code into a same file : class graphic(with no inheritance)
and it seems that I do not have the document locking problem when I open several tabs.

So I will have to find other solutions to share common parts between several applications (maps, table and figure with curves), but I can handle this.

@cmoisy The main thing to consider when having multiple modules in a Bopeh app is that Bokeh objects should not be “module globals”. You need to have functions or other API that your app code can call to get brand new Bokeh objects for every session.

well it should have been:
graph = graphic()
and callbacks triggers update on attributes of that object:
self.fig = figure()
line = self.fig.line

but I have several sub-classes in several files