Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 06fede9

Browse files
committed
Merge pull request #4 from andrewsg/environment
add middleware to monkey-patch os.env to be thread local for GAE compatibility
2 parents 7e4011d + 15665b9 commit 06fede9

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

multicore_runtime/wsgi.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from wsgi_utils import get_module_config_filename
2828
from wsgi_utils import load_user_scripts_into_handlers
2929

30+
from google.appengine.ext.vmruntime import middlewares
3031
from google.appengine.ext.vmruntime import vmconfig
3132
from google.appengine.ext.vmruntime import vmstub
3233

33-
3434
logging.basicConfig(level=logging.INFO)
3535

3636
appinfo_external = get_module_config(get_module_config_filename())
@@ -49,3 +49,19 @@
4949

5050
# Create a "meta app" that dispatches requests based on handlers.
5151
meta_app = dispatcher(preloaded_handlers)
52+
53+
# Wrap meta_app in middleware. The first statement in this section is the
54+
# innermost layer of the middleware, and the last statement is the outermost
55+
# layer (the middleware code that will process a request first). Inside the
56+
# innermost layer is the actual dispatcher, above.
57+
58+
# Adjust SERVER_NAME and SERVER_PORT env vars to hide the service bridge.
59+
meta_app = middlewares.FixServerEnvVarsMiddleware(meta_app)
60+
61+
# Patch os.environ to be thread local, and stamp it with default values based
62+
# on the app configuration. This is for backwards compatibility with GAE's use
63+
# of environment variables to store request data.
64+
# Note: gunicorn "gevent" or "eventlet" workers, if selected, will
65+
# automatically monkey-patch the threading module to make this compatible with
66+
# green threads.
67+
meta_app = middlewares.OsEnvSetupMiddleware(meta_app, appengine_config)

0 commit comments

Comments
 (0)