def launch_gevent_wsgi_server(application, port, max_concurrent_requests,
                              server_name='server', use_pywsgi=False,
                              **kwargs):
  import signal
  import gevent
  from gevent import pool

  if use_pywsgi:
    from gevent import pywsgi
    server_class = pywsgi.WSGIServer
  else:
    from gevent import wsgi
    server_class = wsgi.WSGIServer

  wsgi_server = None
  def _shut_down_wsgi_server():
    """Gracefully terminate the WSGI server when receiving a SIGTERM.
    """
    print 'Stopping %s %s' % (server_class.__module__, server_name)

    if wsgi_server:
      wsgi_server.stop()

  gevent.signal(signal.SIGTERM, _shut_down_wsgi_server)

  print 'Starting %s %s' % (server_class.__module__, server_name)

  try:
    greenlet_pool = pool.Pool(max_concurrent_requests)
    wsgi_server = server_class(
      ('', port), application, spawn=greenlet_pool, log=None, **kwargs)
    wsgi_server.serve_forever()
  except KeyboardInterrupt:
    _shut_down_wsgi_server()
Set up and launch a Gevent WSGI server in the local process.
dataset/ETHPy150Open tellapart/gevent_request_profiler/tellapart/frontend/util.py/launch_gevent_wsgi_server