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


Python server.StreamServer方法代碼示例

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


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

示例1: server

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def server():
    ss = StreamServer(('localhost', PORT), serve).serve_forever() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:4,代碼來源:serverclient.py

示例2: __init__

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def __init__(self, handler):
        self.handler = handler
        self.result = AsyncResult()
        self.server = StreamServer(('127.0.0.1', 0), self) 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:6,代碼來源:mock_server.py

示例3: run_rpc

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def run_rpc(interface_dict):
	print("MpRPC server Started.")
	server_instance = FetchInterfaceClass(interface_dict, "MpRPC")
	mprpc_server = StreamServer(('0.0.0.0', 4315), server_instance)

	gevent.signal(signal.SIGINT, build_mprpc_handler(mprpc_server))
	mprpc_server.serve_forever() 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:9,代碼來源:server.py

示例4: start

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def start(self):
        log.info('starting peermanager')
        # start a listening server
        ip = self.config['p2p']['listen_host']
        port = self.config['p2p']['listen_port']
        log.info('starting listener', host=ip, port=port)
        self.server = StreamServer((ip, port), handle=self._start_peer)
        self.server.start()
        self._bootstrap()
        super(PeerManager, self).start() 
開發者ID:heikoheiko,項目名稱:pydevp2p,代碼行數:12,代碼來源:peermanager.py

示例5: server

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def server():
    server = StreamServer(
        ("127.0.0.1", 4399),
        DogeRPCServer(
            Context(
                URL(None, None, None, {"name": ""}), URL(None, None, None, {})
            ),
            SumServer,
        ),
    )
    g = gevent.spawn(server.serve_forever)
    gevent.sleep(0.1)
    yield server
    g.kill() 
開發者ID:zhu327,項目名稱:doge,代碼行數:16,代碼來源:test_endpoint.py

示例6: run

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def run(sender_config):
    global rpc_server
    try:
        rpc_server = StreamServer((sender_config['host'], sender_config['port']),
                                  handle_api_request)
        rpc_server.start()
        return True
    except Exception:
        logger.exception('Failed binding to sender RPC port')
        return False 
開發者ID:linkedin,項目名稱:iris,代碼行數:12,代碼來源:rpc.py

示例7: main

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def main():
    print('Running on Python %s' % sys.version)

    config = configparser.ConfigParser()
    with open(INI_PATH) as f:
        config.read_file(f)

    ports = Ports(int(config['shared']['port_offset']))

    try:
        udp_proxy_proc1 = sp.Popen('udpproxy.exe %d' % ports['gameserver1'])
        udp_proxy_proc2 = sp.Popen('udpproxy.exe %d' % ports['gameserver2'])

    except OSError as e:
        print('Failed to run udpproxy.exe. Run download_udpproxy.py to download it\n'
              'or build it yourself using the Visual Studio solution in the udpproxy\n'
              'subdirectory and place it in the taserver directory.\n',
              file=sys.stderr)
        return

    server_queue = gevent.queue.Queue()
    firewall = Firewall(ports)
    gevent_spawn('firewall.run', firewall.run, server_queue)

    def handle_client(socket, address):
        msg = TcpMessageReader(socket).receive()
        command = json.loads(msg.decode('utf8'))
        server_queue.put(command)

    server = StreamServer(('127.0.0.1', ports['firewall']), handle_client)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        firewall.remove_all_rules()

    udp_proxy_proc1.terminate()
    udp_proxy_proc2.terminate() 
開發者ID:Griffon26,項目名稱:taserver,代碼行數:39,代碼來源:main.py

示例8: run

# 需要導入模塊: from gevent import server [as 別名]
# 或者: from gevent.server import StreamServer [as 別名]
def run(self):
        servers = []
        ssl_args = {}

        if self.cfg.is_ssl:
            ssl_args = dict(server_side=True, **self.cfg.ssl_options)

        for s in self.sockets:
            s.setblocking(1)
            pool = Pool(self.worker_connections)
            if self.server_class is not None:
                environ = base_environ(self.cfg)
                environ.update({
                    "wsgi.multithread": True,
                    "SERVER_SOFTWARE": VERSION,
                })
                server = self.server_class(
                    s, application=self.wsgi, spawn=pool, log=self.log,
                    handler_class=self.wsgi_handler, environ=environ,
                    **ssl_args)
            else:
                hfun = partial(self.handle, s)
                server = StreamServer(s, handle=hfun, spawn=pool, **ssl_args)

            server.start()
            servers.append(server)

        while self.alive:
            self.notify()
            gevent.sleep(1.0)

        try:
            # Stop accepting requests
            for server in servers:
                if hasattr(server, 'close'):  # gevent 1.0
                    server.close()
                if hasattr(server, 'kill'):  # gevent < 1.0
                    server.kill()

            # Handle current requests until graceful_timeout
            ts = time.time()
            while time.time() - ts <= self.cfg.graceful_timeout:
                accepting = 0
                for server in servers:
                    if server.pool.free_count() != server.pool.size:
                        accepting += 1

                # if no server is accepting a connection, we can exit
                if not accepting:
                    return

                self.notify()
                gevent.sleep(1.0)

            # Force kill all active the handlers
            self.log.warning("Worker graceful timeout (pid:%s)" % self.pid)
            [server.stop(timeout=1) for server in servers]
        except:
            pass 
開發者ID:jpush,項目名稱:jbox,代碼行數:61,代碼來源:ggevent.py


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