Can gevent workers be used in the python 3 app engine standard environment?

Viewed 1272

Attempting to use them gives me the following error:

Traceback (most recent call last):
  File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 196, in init_process
    self.patch()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 75, in patch
    fileno=s.sock.fileno()))
  File "/env/lib/python3.7/site-packages/gevent/_socket3.py", line 114, in __init__
    self._sock = self._gevent_sock_class(family, type, proto, fileno)
OSError: [Errno 92] Protocol not available: 'protocol'

Are sockets not supported in the python 3 environment? Is this the reason it won't work?

My application spends a lot of time blocked on other web servers, so using async workers is necessary for decent performance. In the meantime I will try using eventlet workers instead.

EDIT: Including some more context around usage

app.yaml

runtime: python37
instance_class: F2

entrypoint: gunicorn -c gunicorn.conf.py -b :$PORT my_project.server:app

gunicorn.conf.py

# Recommended number of workers based on instance size:
# https://cloud.google.com/appengine/docs/standard/python3/runtime#entrypoint_best_practices
workers = 2
# Use an asynchronous worker as most of the work is waiting for websites to load
worker_class = 'gevent'

Since it is during gunicorn launch I don't believe the app definition context will be useful. However for completeness I'm launching a basic flask application. Something like:

my_project/server.py

from flask import Flask

from my_project.handlers import run

app = Flask(__name__)
app.register_blueprint(run, url_prefix='/run')
1 Answers

I had the same error. I think we are limited to GAE Flexible or Cloud Run on GKE if we want to use gevent.

GAE Standard runs in a sandbox (gVisor) and some operations are limited (I noticed this trying Cloud Run which had the same issue with gevent)

The error you are seeing is this one:

Container Sandbox Limitation: Unsupported syscall 
getsockopt(0x5,0x1,0x26,0x7e11bd8ddf20,0x7e11bd8ddf24,0x4)
Related