Search code examples
pylonsturbogears2

How to register tg app_globals on a worker thread?


I have a turbogears app that makes extensive use of app_globals.

It uses common code that does "from tg import app_globals" and then uses the object.

Until now, this common code was only called in the context of an incoming request.

however, I now want to start worker threads in the app to do processing, and these worker threads needs to call the common code.

How do I register the same "tg.app_globals" on the worker thread?

I am trying to avoid rewriting all my common code to pass around an "app_globals" object.


Solution

  • TurboGears configuration is always available in any thread after it got processed, so unless you need to access the app_globlas before the configuration process took place you can do that through tg.config['tg.app_globals']