I'm working on a GAE app and I want to do a one time initialization where I set some global variables. Currently I just do that in main.py, but it seems like the correct way to do this sort of thing is with Warmup Requests.
Where is the best place to put one-time and every-time code in GAE/Python?
https://developers.google.com/appengine/docs/adminconsole/instances#Loading_Requests
Can somebody explain to me a bit more in detail where the code should go to make this work using webapp2? In the simple use case, I just want to set a global variable that has a list of names and be able to access it anywhere else in the app. For instance:
# init code
NAMES = ['u1', 'u2', 'u3']
# somewhere else in the app
if 'u1' in NAMES:
# do stuff
Put you initialisation phase in a module. Save the values in the module at import time Then import it in appengine_config.py it is always loaded before any of your code.
https://developers.google.com/appengine/docs/python/tools/appengineconfig
Then elsewhere in you code import the module and referent to the name in you case .NAMES for instance
Put code in you initialisation phase that only does the work once.