Updating from Unlocked Callbacks and using yield with executor?

Hi all,
Referring to the sample code in this link here, Running a Bokeh server — Bokeh 2.4.2 Documentation

I’m having trouble figuring out when the thread actually starts execution. For this portion here:

# this unlocked callback will not prevent other session callbacks from
# executing while it is in flight
@gen.coroutine
@without_document_lock
def unlocked_task():
    global i
    i += 1
    res = yield executor.submit(blocking_task, i)
    doc.add_next_tick_callback(partial(locked_update, i=res))

I hope my question isn’t confusing…
With the generator, does the executor start running blocking_task(i) when i is evaluated to res on the this line?
doc.add_next_tick_callback(partial(locked_update, i=res))
Does add_next_tick_callback not get called until the blocking_task executor returns the result?

With the generator, does the executor start running blocking_task(i) when i is evaluated to res on the this line?

@Ronald_Truong AFAIK that’s a reasonably accurate description, but really the exact details of this is a Tornado question since the executors are part of the Tornado API, not Bokeh’s. E.g. I think there are pooled executors which means a thread might not be immediately available.

Does add_next_tick_callback not get called until the blocking_task executor returns the result?

This definitely true, though.

1 Like