當前位置: 首頁>>代碼示例>>Python>>正文


Python gevent.pywsgi方法代碼示例

本文整理匯總了Python中gevent.pywsgi方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.pywsgi方法的具體用法?Python gevent.pywsgi怎麽用?Python gevent.pywsgi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gevent的用法示例。


在下文中一共展示了gevent.pywsgi方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: server_handler

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
def server_handler(args):
    """server_handler."""
    if not db.setup(url=args.db, echo=args.db_echo):
        return
    if not _check_db_revision():
        return

    app = create_app()
    listener = '{:s}:{:d}'.format(args.host, args.port)
    if args.debug:
        logging.getLogger('werkzeug').disabled = True
        set_loglevel(logging.DEBUG)
        app.config['ENV'] = 'development'
        app.debug = True

        _show_banner_debug(app, listener)
        from werkzeug.serving import run_simple
        run_simple(
            args.host, args.port, app, use_reloader=True, use_debugger=True,
            threaded=True)
    else:
        app.config['ENV'] = 'production'
        import gevent
        from gevent.pywsgi import WSGIServer
        http_server = WSGIServer(listener, application=app, log=None)

        def stop_server():
            if http_server.started:
                http_server.stop()

        gevent.signal(signal.SIGTERM, stop_server)
        gevent.signal(signal.SIGINT, stop_server)
        logger.info(' * Environment: {}'.format(app.config['ENV']))
        logger.info(' * Running on http://{}/ (Press CTRL+C to quit)'.format(
            listener))

        try:
            http_server.serve_forever()
        except (KeyboardInterrupt, SystemExit):
            stop_server() 
開發者ID:chainer,項目名稱:chainerui,代碼行數:42,代碼來源:app.py

示例2: serve_forever

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
def serve_forever():
    gevent.spawn(daemon)
    print web
    application = web.application(urls, globals()).wsgifunc()
    print 'Serving on 8888'
    server = gevent.pywsgi.WSGIServer(('', 8888), application)
    server.serve_forever() 
開發者ID:isombyt,項目名稱:XiaQian,代碼行數:9,代碼來源:WebManager.py

示例3: run

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
def run(self) -> None:
        """
        Starts all poller instances.
        After that, polling is performed in regular intervals specified by the polling_delay_ms property.
        By default this function blocks the current thread.
        """
        self._validation_service.validate_all_addresses()

        self._logger.info("Gateway Application started")

        task_group = gevent.pool.Group()

        gevent.signal(signal.SIGINT, self._coin_transaction_polling_service.cancel)
        gevent.signal(signal.SIGINT, self._waves_transaction_polling_service.cancel)

        task_group.start(self._coin_transaction_polling_service)
        task_group.start(self._waves_transaction_polling_service)

        attempt_list_workers = self._create_attempt_list_workers()

        for worker in attempt_list_workers:
            gevent.signal(signal.SIGINT, worker.cancel)
            task_group.start(worker)

        http = gevent.pywsgi.WSGIServer(
            (self._host, self._port), self._flask, log=gevent.pywsgi.LoggingLogAdapter(self._logger.getChild('pywsgi')))

        gevent.signal(signal.SIGINT, http.close)

        self._logger.info('Listening on %s:%s', self._host, str(self._port))

        http.serve_forever()

        task_group.join(raise_error=True) 
開發者ID:jansenmarc,項目名稱:WavesGatewayFramework,代碼行數:36,代碼來源:gateway_application_service.py

示例4: run_application

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
def run_application(self):
        path = self.environ.get('PATH_INFO')
        content_type = self.server.data_handlers.get(path)
        if content_type is not None:
            self.serve_file(basename(path), content_type)
            return

        websocket_mode = False

        if WebSocket.is_socket(self.environ):
            self.status = 'websocket'
            self.log_request()
            self.environ['websocket'] = WebSocket(self.environ, self.socket, self.rfile)
            websocket_mode = True
        try:
            self.result = self.application(self.environ, self.start_response)
            if self.result is not None:
                self.process_result()
        except:
            websocket = self.environ.get('websocket')
            if websocket is not None:
                websocket.close()
            raise
        finally:
            if websocket_mode:
                # we own the socket now, make sure pywsgi does not try to read from it:
                self.socket = None 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:29,代碼來源:server.py

示例5: test_wsgi_scenario

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
def test_wsgi_scenario(self):
        from gevent.pywsgi import WSGIServer

        def serve(http_server):
            http_server.serve_forever()

        def hello_world(environ, start_response):
            # Generate response in child process.
            with pipe() as (reader, writer):
                start_response('200 OK', [('Content-Type', 'text/html')])
                rg = start_process(
                    target=complchild_test_wsgi_scenario_respgen,
                    args=(writer, ))
                response = reader.get()
                rg.join()
                assert rg.exitcode == 0
            return [response]

        # Call `urlopen` with `None` in the parent before forking. This works
        # around a special type of segfault in the child after fork on MacOS.
        # Doh! See https://bugs.python.org/issue27126 and
        # https://github.com/jgehrcke/gipc/issues/52
        try:
            import urllib.request as request
        except ImportError:
            import urllib2 as request
        try:
            result = request.urlopen(None)
        except AttributeError:
            pass

        http_server = WSGIServer(('localhost', 0), hello_world)
        servelet = gevent.spawn(serve, http_server)
        # Wait for server being bound to socket.
        while True:
            if http_server.address[1] != 0:
                break
            gevent.sleep(0.05)
        client = start_process(
            target=complchild_test_wsgi_scenario_client,
            args=(http_server.address, ))
        client.join()
        assert client.exitcode == 0
        servelet.kill()
        servelet.get()  # get() is join and re-raises Exception. 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:47,代碼來源:test_gipc.py


注:本文中的gevent.pywsgi方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。