How to use the gevent.pywsgi.WSGIServer function in gevent

To help you get started, we’ve selected a few gevent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plivo / plivoframework / src / plivo / rest / freeswitch / apiserver.py View on Github external
self.fs_host, fs_port = self.fs_inbound_address.split(':', 1)
                self.fs_port = int(fs_port)

                self.fs_password = config.get('rest_server', 'FS_INBOUND_PASSWORD')

                # get outbound socket host/port
                self.fs_out_address = config.get('outbound_server', 'FS_OUTBOUND_ADDRESS')
                self.fs_out_host, self.fs_out_port  = self.fs_out_address.split(':', 1)

                # if outbound host is 0.0.0.0, send to 127.0.0.1
                if self.fs_out_host == '0.0.0.0':
                    self.fs_out_address = '127.0.0.1:%s' % self.fs_out_port
                # set wsgi mode
                _wsgi_mode = config.get('rest_server', 'WSGI_MODE', default='wsgi')
                if _wsgi_mode in ('pywsgi', 'python', 'py'):
                    self._wsgi_mode = PyWSGIServer
                else:
                    self._wsgi_mode = WSGIServer
                # set ssl or not
                self._ssl = config.get('rest_server', 'SSL', default='false') == 'true'
                self._ssl_cert = config.get('rest_server', 'SSL_CERT', default='')


            self.default_answer_url = config.get('common', 'DEFAULT_ANSWER_URL')

            self.default_hangup_url = config.get('common', 'DEFAULT_HANGUP_URL', default='')

            self.default_http_method = config.get('common', 'DEFAULT_HTTP_METHOD', default='')
            if not self.default_http_method in ('GET', 'POST'):
                self.default_http_method = 'POST'

            self.extra_fs_vars = config.get('common', 'EXTRA_FS_VARS', default='')
github miguelgrinberg / python-socketio / examples / server / wsgi / django_example / socketio_app / management / commands / runserver.py View on Github external
eventlet.wsgi.server(eventlet.listen(('', 8000)), application)
        elif sio.async_mode == 'gevent':
            # deploy with gevent
            from gevent import pywsgi
            from django_example.wsgi import application
            try:
                from geventwebsocket.handler import WebSocketHandler
                websocket = True
            except ImportError:
                websocket = False
            if websocket:
                pywsgi.WSGIServer(
                    ('', 8000), application,
                    handler_class=WebSocketHandler).serve_forever()
            else:
                pywsgi.WSGIServer(('', 8000), application).serve_forever()
        elif sio.async_mode == 'gevent_uwsgi':
            print('Start the application through the uwsgi server. Example:')
            print('uwsgi --http :5000 --gevent 1000 --http-websockets '
                  '--master --wsgi-file django_example/wsgi.py --callable '
                  'application')
        else:
            print('Unknown async_mode: ' + sio.async_mode)
github ryanj / flask-postGIS / app.py View on Github external
ip = map.app.config['IP']
   app_name = map.app.config['APP_NAME']
   host_name = map.app.config['HOST_NAME']

   fwtype="wsgiref"
   for fw in ("gevent", "cherrypy", "flask"):
      try:
         imp.find_module(fw)
         fwtype = fw
      except ImportError:
         pass

   print('Starting WSGIServer type %s on %s:%d ... ' % (fwtype, ip, port))
   if fwtype == "gevent":
      from gevent.pywsgi import WSGIServer
      WSGIServer((ip, port), map.app).serve_forever()

   elif fwtype == "cherrypy":
      from cherrypy import wsgiserver
      server = wsgiserver.CherryPyWSGIServer(
         (ip, port), map.app, server_name=host_name)
      server.start()

   elif fwtype == "flask":
      from flask import Flask
      server = Flask(__name__)
      server.wsgi_app = map.app
      server.run(host=ip, port=port)

   else:
      from wsgiref.simple_server import make_server
      make_server(ip, port, map.app).serve_forever()
github voussoir / else / Templates / flask / flasksite_launch.py View on Github external
import sys

if len(sys.argv) == 2:
    port = int(sys.argv[1])
else:
    port = 5000

if port == 443:
    http = gevent.pywsgi.WSGIServer(
        listener=('0.0.0.0', port),
        application=flasksite.site,
        keyfile='https\\flasksite.key',
        certfile='https\\flasksite.crt',
    )
else:
    http = gevent.pywsgi.WSGIServer(
        listener=('0.0.0.0', port),
        application=flasksite.site,
    )


print('Starting server on port %d' % port)
http.serve_forever()
github stanfordnlp / cocoa / cocoa / web / start_app.py View on Github external
app.config['schema'] = schema
    app.config['user_params'] = params
    app.config['sessions'] = defaultdict(None)
    app.config['controller_map'] = defaultdict(None)
    app.config['instructions'] = instructions
    app.config['task_title'] = params['task_title']


    if 'icon' not in params.keys():
        app.config['task_icon'] = 'handshake.jpg'
    else:
        app.config['task_icon'] = params['icon']

    print "App setup complete"

    server = WSGIServer(('', args.port), app, log=WebLogger.get_logger(), error_log=error_log_file)
    atexit.register(cleanup, flask_app=app)
    server.serve_forever()
github apollo-ng / PiGI / software / pyGI / geigerserver.py View on Github external
def start(g,gl):
    global geiger, geigerlog, clients_handler
    geiger = g
    geigerlog = gl
    clients_handler = geigerclient.ClientsHandler(geiger,geigerlog)

    ip = cfg.get('server','ip')
    port = cfg.getint('server','port')
    log.info("listening on %s:%d" % (ip, port))

    server = WSGIServer((ip, port), app,
                        handler_class=WebSocketHandler)
    server.serve_forever()
github rotki / rotki / rotkehlchen / api / server.py View on Github external
def start(self, host: str = '127.0.0.1', port: int = 5042) -> None:
        """This is used to start the API server in production"""
        wsgi_logger = logging.getLogger(__name__ + '.pywsgi')
        self.wsgiserver = WSGIServer(
            (host, port),
            self.flask_app,
            log=wsgi_logger,
            error_log=wsgi_logger,
        )
        msg = f'Rotki API server is running at: {host}:{port}'
        print(msg)
        log.info(msg)
        self.wsgiserver.start()
github artisan-roaster-scope / artisan / src / artisanlib / weblcds.py View on Github external
def work(p,rp,nonesym,timec,timebg,btc,btbg,etc,etbg,showetflag,showbtflag):
    global port, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showbt, showet
    port = p
    static_path = rp
    nonesymbol = nonesym
    timecolor = timec
    timebackground = timebg
    btcolor = btc
    btbackground = btbg
    etcolor = etc
    etbackground = etbg
    showet = showetflag
    showbt = showbtflag
    TEMPLATE_PATH.insert(0,rp)
    s = WSGIServer(("0.0.0.0", p), default_app(), handler_class=WebSocketHandler)
    s.serve_forever()
github moses-palmer / virtual-touchpad / lib / virtualtouchpad / server / __init__.py View on Github external
import sys

    try:
        from geventwebsocket.handler import WebSocketHandler
    except ImportError:
        from geventwebsocket import WebSocketHandler

    # Importing this module will attach routes to app
    from . import routes

    sys.stdout.write('Starting server http://%s:%d/...\n' % (
        address, port))

    from gevent import monkey
    monkey.patch_all(thread=False)
    return gevent.pywsgi.WSGIServer(
        ('0.0.0.0', port),
        app,
        handler_class=WebSocketHandler)
github wushirenfei / k8s-web-terminal / app.py View on Github external
def run_server():
    app.debug = True
    from gevent import pywsgi
    from geventwebsocket.handler import WebSocketHandler
    server = pywsgi.WSGIServer(
        listener = ('0.0.0.0', 5000),
        application=app,
        handler_class=WebSocketHandler)
    server.serve_forever()