散景和Joblib不在一起玩 [英] Bokeh and Joblib don't play together

查看:67
本文介绍了散景和Joblib不在一起玩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Bokeh脚本,该脚本使用包裹在joblib的@memory.cache装饰器中的函数来调用数据.当我将脚本作为python脚本运行时,get_data函数很快(已缓存).当我使用bokeh server --show code.py调用它时,似乎丢失了缓存并重新评估了该函数,从而使数据检索变慢.如何使Bokeh与Joblib很好地配合?

I have a Bokeh script which calls the data using a function wrapped with joblib's @memory.cache decorator. When I run the script as a python script the get_data function is fast (cached). When I call it using bokeh server --show code.py it seems like cache is lost and the function is re-evaluated, making data retrieval slow. How can I make Bokeh work nicely with Joblib?

推荐答案

如果不能运行一个可以重现您所看到内容的示例,则很难确定.但是我的猜测是,它与Bokeh服务器代码运行器在每个会话上执行应用脚本的方式有关.

It's hard to say for certain without being able to run an example that reproduces what you are seeing. But my guess is that it has something to do with the way the Bokeh server code runner executes the app script, on every session.

因此,我可以考虑尝试一些可能的事情.

So, I can think of a few possible things to try.

首先,从0.12.4开始,有

First, as of 0.12.4 there's examples and guidance for embedding a Bokeh server as a library e.g. in a standalone python script, or in a Flask or Tornado app. The examples there all also use FunctionHandler which does not exec. My hunch is that this is more like the standard single process/single namespace python execution model, and will play better with your joblib decorator.

(如果您尝试使用此方法,并且可以使用,请以某种方式告知使用,可能值得更好地进行记录.)

(If you try this route, and it works, please let use know somehow, it's probably worth documenting better.)

否则,另一个可能会更好的选择是使用频谱图示例中看到此技术(参见audio.py)

Otherwise, another option that might work better is to use lifecycle hooks to provide your wrapped function in a way that is sure to be shared across sessions. You can see this technique in the spectrogram example (c.f. the audio.py)

最后,对SO提出一些温和的建议.如果您可以包括最少的示例代码,那么将大大增加能够将代码返回到答案中的几率.例如,如果这里有示例代码可以尝试工作,那么我就可以在答案中发布完整的工作代码.

Finally, just some gentle advice for SO. If you can include a minimal example code, that greatly increases the odds of being able to get code back in an answer. E.g., if there was example code here that I could try to get working, then I'd be able to post a complete working code in the answer.

这篇关于散景和Joblib不在一起玩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆