How to disable a button while its callback it running?

Is it possible to disable a button right after clicking it and then enable it again after the on_click callback is finished?

Here’s a code that will demonstrate the scenario:

from bokeh.models.widgets.buttons import Button
from time import sleep
from bokeh.io import curdoc

# button
button = Button(
    label="Test", 
    button_type='primary', 
    name="button"
)

# callback
def on_button_click():
    button.disabled=True
    sleep(10)
    button.disabled=False

button.on_click(on_button_click)

curdoc().add_root(button)

Wrap everything after button.disabled=True in a function, and pass that function to curdoc().add_next_tick_callback.

@p-himik
Thanks for your reply!
I modified the code like you said (if I understood correctly) but now the button is disabled but the next_tick function isn’t being invoked.

from bokeh.models.widgets.buttons import Button
from time import sleep
from bokeh.io import curdoc

# button
button = Button(
    label="Test", 
    button_type='primary', 
    name="button"
)

# callback
def on_button_click():
    button.disabled=True

def next_tick():
    sleep(2)
    button.disabled=False

button.on_click(on_button_click)

curdoc().add_root(button)
curdoc().add_next_tick_callback(next_tick)

The add_next_tick_callback line should be the last in on_button_click, not in the file.

@p-himik
sweet thanks!