title: flask socketIO app with gunicorn and eventlet, running on AWS Elastic beanstalk
body: <p>My application works fine without gunicorn and eventlet, in development mode.
  With the command: <code>python3 application.py</code> everything runs just fine.
  When I run the app with <code>gunicorn --worker-class eventlet -w 1 application:application</code>, some functions don't work at all. The app still works fine, but I can't call AWS services, send email using SMTP library, or use requests library, etc. These problems occur only with eventlet/gunicorn and not with <code>socketio.run(app)</code>.</p>
  <p>When I run my app with <code>gunicorn --worker-class eventlet -w 1 application:application</code>, I get:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py&quot;, line 583, in spawn_worker
      worker.init_process()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/workers/geventlet.py&quot;, line 99, in init_process
      super().init_process()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py&quot;, line 119, in init_process
      self.load_wsgi()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py&quot;, line 144, in load_wsgi
      self.wsgi = self.app.wsgi()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py&quot;, line 67, in wsgi
      self.callable = self.load()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py&quot;, line 49, in load
      return self.load_wsgiapp()
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py&quot;, line 39, in load_wsgiapp
      return util.import_app(self.app_uri)
    File &quot;/usr/local/lib/python3.6/site-packages/gunicorn/util.py&quot;, line 358, in import_app
      mod = importlib.import_module(module)
    File &quot;/usr/lib64/python3.6/importlib/__init__.py&quot;, line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 994, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 971, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 955, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 665, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 678, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/home/ec2-user/environment/cognito/application.py&quot;, line 15, in &lt;module&gt;
      JWKS = requests.get(JWKS_URL).json()[&quot;keys&quot;]
    File &quot;/usr/local/lib/python3.6/site-packages/requests/api.py&quot;, line 72, in get
      return request('get', url, params=params, **kwargs)
    File &quot;/usr/local/lib/python3.6/site-packages/requests/api.py&quot;, line 58, in request
      return session.request(method=method, url=url, **kwargs)
    File &quot;/usr/local/lib/python3.6/site-packages/requests/sessions.py&quot;, line 508, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;/usr/local/lib/python3.6/site-packages/requests/sessions.py&quot;, line 618, in send
      r = adapter.send(request, **kwargs)
    File &quot;/usr/local/lib/python3.6/site-packages/requests/adapters.py&quot;, line 440, in send
      timeout=timeout
    File &quot;/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py&quot;, line 601, in urlopen
      chunked=chunked)
    File &quot;/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py&quot;, line 346, in _make_request
      self._validate_conn(conn)
    File &quot;/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py&quot;, line 850, in _validate_conn
      conn.connect()
    File &quot;/usr/local/lib/python3.6/site-packages/urllib3/connection.py&quot;, line 314, in connect
      cert_reqs=resolve_cert_reqs(self.cert_reqs),
    File &quot;/usr/local/lib/python3.6/site-packages/urllib3/util/ssl_.py&quot;, line 269, in create_urllib3_context
      context.options |= options
    File &quot;/usr/lib64/python3.6/ssl.py&quot;, line 465, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;/usr/lib64/python3.6/ssl.py&quot;, line 465, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    File &quot;/usr/lib64/python3.6/ssl.py&quot;, line 465, in options
      super(SSLContext, SSLContext).options.__set__(self, value)
    [Previous line repeated 317 more times]
  RecursionError: maximum recursion depth exceeded while calling a Python object
  </code></pre>
  <p>In the above example I am using requests library.</p>
  <p>When I try to send mails using SMTP Library, I get:</p>
  <pre><code>File &quot;/home/vasudeva/Codes/sanskrit/application.py&quot;, line 2115, in recover
      if util.sendemail(user.email, code):
    File &quot;/home/vasudeva/Codes/sanskrit/util.py&quot;, line 112, in sendemail
      server = smtplib.SMTP(HOST, PORT)
    File &quot;/usr/lib/python3.7/smtplib.py&quot;, line 251, in __init__
      (code, msg) = self.connect(host, port)
    File &quot;/usr/lib/python3.7/smtplib.py&quot;, line 336, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File &quot;/usr/lib/python3.7/smtplib.py&quot;, line 307, in _get_socket
      self.source_address)
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/green/socket.py&quot;, line 44, in create_connection
      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 517, in getaddrinfo
      qname, addrs = _getaddrinfo_lookup(host, family, flags)
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 490, in _getaddrinfo_lookup
      raise err
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 479, in _getaddrinfo_lookup
      answer = resolve(host, qfamily, False, use_network=use_network)
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 432, in resolve
      raise EAI_EAGAIN_ERROR
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 479, in _getaddrinfo_lookup
      answer = resolve(host, qfamily, False, use_network=use_network)
    File &quot;/home/vasudeva/Codes/sanskrit/env/lib/python3.7/site-packages/eventlet/support/greendns.py&quot;, line 432, in resolve
      raise EAI_EAGAIN_ERROR
  socket.gaierror: [Errno -3] Lookup timed out
  </code></pre>
  <p>As everything works fine without gunicorn/eventlet. So I created a simple test app without websockets. The problem is still there. App works fine with <code>flask run</code> command but the moment I run the app with Gunicorn command some features don't work.</p>