Time difference between button clicked and the first line in the invoked function

Hi,

My situation
In my app there is about 3-4 secs gap from the time a button is clicked and the plots displayed. Though the time gap is not too bad, it is enough to create a doubt even in my mind if the application is working or is stuck. This is mainly bcos the mouse doesn’t show any indication.

What I tried:
So I am trying to provide a ‘Please wait…’ kind of a message after the button is clicked. I created a Div of ‘wait’ text with visibility set to False and the very first line in myfunction I set it to True.

The code which invokes myfunction that creates plots.
mybutton.on_click(myfunction)

The very first line sets it to true

def myfunction():
    waittxt.visible = True # show wait msg to user.

Where I need help
The issue is that this msg is getting displayed after nearly 2-3 seconds. And within 0.5-1.0 secs of that msg displayed the plots are displayed. Even a 3-word message disappears even before one can read it.

My main intention is to get the msg displayed ‘as soon as the button is clicked’ and not 2-3 secs later. Given that the very first line in my invoked function is to set this text to true, I am wondering if those initial 2-3 secs are spent on something else. Since my code is too big I am not pasting it here, but I am open to do screenshare offline (over zoom etc.) if needed.

Any tips on this are greatly appreciated.
cheers.

It is impossible to speculate without a Minimal Reproducible Example

Sure. Just wanted to give it a shot, in case there are some different aspects of curdoc that I don’t know. Since it’s not possible to reproduce the delay without actually putting the entire code here, we can close this ticket.

@Gopi_M

Some ideas (without the benefit of a minimal reproducible example) …

  1. Rework your callback so that the logic after setting the Div model to visible so all remaining code in the current callback is invoked via a add_next_tick_callback(…)

  2. Use panel at the top-level of your code … it can be used as a thin wrapper to bokeh and the panel server is the bokeh server. Panel includes a LoadingSpinner widget that can indicate busy state.

    https://panel.holoviz.org/reference/indicators/LoadingSpinner.html

Regarding 1, I think what might be happening is similar to the behavior discussed in this Discourse topic.

https://discourse.bokeh.org/t/div-not-updating-immediately/4134

Thanks @_jm Will try to check this in the coming days.