Search code examples
pythonmultithreadingpylonswsgi

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


Solution

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