本文整理汇总了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()
示例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)
示例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()
示例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()
示例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()
示例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
示例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()
示例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