Python gevent.server.StreamServer() Examples
The following are 9
code examples of gevent.server.StreamServer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gevent.server
, or try the search function
.
Example #1
Source File: serverclient.py From gipc with MIT License | 23 votes |
def server(): ss = StreamServer(('localhost', PORT), serve).serve_forever()
Example #2
Source File: server.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #3
Source File: mock_server.py From gnsq with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, handler): self.handler = handler self.result = AsyncResult() self.server = StreamServer(('127.0.0.1', 0), self)
Example #4
Source File: peermanager.py From pydevp2p with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #5
Source File: test_endpoint.py From doge with Apache License 2.0 | 5 votes |
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()
Example #6
Source File: test_ha.py From doge with Apache License 2.0 | 5 votes |
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()
Example #7
Source File: rpc.py From iris with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #8
Source File: main.py From taserver with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #9
Source File: ggevent.py From jbox with MIT License | 4 votes |
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