managed VMs use threading even with threadsafe: false ? (python27, webapp2)

92 views
Skip to first unread message

Adam Sah

unread,
Mar 6, 2016, 11:41:56 AM3/6/16
to Google App Engine
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


Adam (Cloud Platform Support)

unread,
Mar 14, 2016, 12:24:59 PM3/14/16
to Google App Engine
It's a known issue that Managed VMs don't respect 'threadsafe' and this is mentioned in an issue on GitHub, though these details are specific to the Java runtime. Regarding your workaround I don't see any issues with it.

Adam Sah

unread,
Mar 14, 2016, 5:06:57 PM3/14/16
to google-a...@googlegroups.com
thanks!  would it be possible to copy the relevant "gotcha" issues to the core docs or have an "errata" page with workarounds?  I spent hours tracking this down, and it seems unreasonable to require new users (of Managed VMs) to read through every bug report... :-(

another example: Images API not supported yet....

thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/MuaRKGy2YAw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/0962c27b-cfda-4622-9a91-198619d083d3%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Adam (Cloud Platform Support)

unread,
Mar 18, 2016, 1:59:21 PM3/18/16
to Google App Engine, as...@midgard.net
Yes, I can submit a request to the documentation team. You can also use the 'Send feedback' link at the top of any documentation page to submit feedback through the same channels.


On Monday, March 14, 2016 at 5:06:57 PM UTC-4, Adam Sah wrote:
thanks!  would it be possible to copy the relevant "gotcha" issues to the core docs or have an "errata" page with workarounds?  I spent hours tracking this down, and it seems unreasonable to require new users (of Managed VMs) to read through every bug report... :-(

another example: Images API not supported yet....

thanks!

To unsubscribe from this group and all its topics, send an email to google-appengine+unsubscribe@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages