简体   繁体   中英

Creating a Pylons Thread with Access to app_globals

I'd like to create a process that runs in the background of my pylons environment, unbound to client requests, with access to the pylons app_globals object. The general purpose of the process is to check client sessions for expiration and perform some post-expiration analysis.

Is this possible? I've tried creating a thread in the config/environment.py file but when I try to access properties of app_globals I get the following error:

TypeError: No object (name: app_globals) has been registered for this thread

Thanks in advance,
Will

您需要注册app_globals(在每个请求注册的pylons app_globals中):

pylons.app_globals._push_object(config['pylons.app_globals'])

The object you are trying to access is StackedObjectProxy registered by pylons for every request, for the serving thread.

If you only intend to read it, it is safe to use the one in config:

config.get('pylons.app_globals') or config.get('pylons.g')

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