Is anyone else seeing this? I noticed that global variables were getting modified mid-execution and then confirmed by checking os.getpid() and saw the same process IDs in two concurrent requests (using time.sleep() to force concurrency)
Meanwhile, I drafted up a quick workaround - it seems to work, but I'd love a code review!
import logging
from os import getpid
from threading import Lock
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
...
class SingleThreadedWSGIApplication(webapp.WSGIApplication):
def __init__(self, *args, **kwargs):
self.lock = Lock()
super(SingleThreadedWSGIApplication, self).__init__(*args, **kwargs)
def __call__(self, environ, start_response):
logging.warning("SingleThreadedWSGIApplication.__call__(). pid=%d" % getpid())
with self.lock:
return super(SingleThreadedWSGIApplication, self).__call__(environ, start_response)
def is_production():
...bunch of custom environment checks...
PATHS=[ ... ]
app = SingleThreadedWSGIApplication(PATHS, debug=(not is_production()))
def main():
...
run_wsgi_app(app)
if __name__ == "__main__":
main()
relevant parts of app.yaml:
runtime: python-compat
vm: true
entrypoint: gunicorn -b :$PORT main:app
threadsafe: false
api_version: 1
instance_class: F4