开发者

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


You need register app_globals (in pylons app_globals registerd per request):

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')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜