从单独的线程访问 app_globals
我想在我的 Pylons 项目中创建一个单独的线程来进行繁重的计算,通过 python Queue 对象与之交互。问题是我需要访问 app_globals 对象。当我尝试这样做时,我得到了
TypeError: No object (name: app_globals) has been registered for this thread
我也尝试以这种方式访问app_globals:
app_globals = config.get('pylons.app_globals')
self.cadfile = app_globals.pm.get_upload_path(session, 'cadfile')
但随后我收到另一个错误:
AttributeError: 'NoneType' object has no attribute 'pm'
如何从单独的线程访问app_globals?
I'd like to create a separate thread for heavy computations in my Pylons project interacting with it through python Queue object. The problem is that I need to get to the app_globals object. When I try to do that, i get a
TypeError: No object (name: app_globals) has been registered for this thread
I also tried to access app_globals in this way:
app_globals = config.get('pylons.app_globals')
self.cadfile = app_globals.pm.get_upload_path(session, 'cadfile')
but then I get another error:
AttributeError: 'NoneType' object has no attribute 'pm'
How should I access app_globals from a separate thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能您必须将 app_globals 作为启动参数传递给线程或通过队列传递它?我不确定,但我认为 app_globals 实现为 threading.local
例如。
May be you must pass app_globals to thread as a start parameter or pass it through a queue? I not shure, but I think that app_globals implemented as threading.local
Eg.