散景装饰器 @without_document_lock() 是什么意思?

What does the bokeh decorator @without_document_lock() mean?

bokeh server documentation 包含一个 从未锁定的回调更新的示例。 它指出:

Normally Bokeh session callbacks recursively lock the document until all future work they initiate is complete. However, you may want to drive blocking computations from callbacks using Tornado’s ThreadPoolExecutor in an asynchronous callback. This can work, but requires the Bokeh provided without_document_lock() decorator to suppress the normal locking behavior.

这是什么意思?这是否意味着,例如,如果没有装饰器,那么一旦调用,回调和它调用的任何东西都会在将控制权交还给主 IOLoop 之前运行完成?

而对于装饰器,主事件循环在回调执行时继续?

What does this mean? Does it mean, for example, that without the decorator, then once invoked, a callback and anything it calls runs to completion before surrendering control back to the main IOLoop?

这意味着当另一个 Bokeh 回调正在运行并锁定 Document 时,甚至不会开始执行其他 Bokeh 回调,无论它们是否在不同的线程上。

但是您可以覆盖它,例如如果您在执行昂贵 "non-Bokeh" 计算的线程上有回调,则在最后更新一些 Bokeh 属性。你可以装饰那个回调 成为 @without_document_lock(),因此它始终可以启动并在后台执行昂贵的 "non-Bokeh work",而不管可能正在执行的任何其他 Bokeh 回调。您只需遵循 link 中的模式并将任何实际的 Bokeh 属性 更新放入 "next tick" 回调中(对 Bokeh 模型的所有实际更新都必须发生在具有文档锁的回调中,就像下一个报价回调)