开发者

Accessing app_globals from a separate thread

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.ge开发者_JS百科t_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?


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.

class MyWorker(threading.Thread):
    def __init__(self, local_app_globals, *args, **kwargs):
        self.app_globals=local_app_globals
        super(MyWorker, self).__init__(*args, **kwargs)

    def run():
        #use self.app_globals as app_globals

t=MyWorker(app_globals)
t.start()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜