简体   繁体   中英

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.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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM