def server(sock, site, log=None, max_size=512, serv=None, max_http_version=DEFAULT_MAX_HTTP_VERSION): pool = Pool(max_size=max_size) if serv is None: serv = Server(sock, sock.getsockname(), site, log, max_http_version=max_http_version) try: serv.log.write("httpd starting up on %s\n" % (sock.getsockname(), )) while True: try: new_sock, address = sock.accept() proto = HttpProtocol(new_sock, address, serv) pool.execute_async(proto.handle) api.sleep(0) # sleep to allow other coros to run except KeyboardInterrupt: api.get_hub().remove_descriptor(sock.fileno()) serv.log.write("httpd exiting\n") break finally: try: sock.close() except socket.error: pass
def server(sock, site, log=None, environ=None, max_size=None, max_http_version=DEFAULT_MAX_HTTP_VERSION, protocol=HttpProtocol, server_event=None, minimum_chunk_size=None): serv = Server(sock, sock.getsockname(), site, log, environ=None, max_http_version=max_http_version, protocol=protocol, minimum_chunk_size=minimum_chunk_size) if server_event is not None: server_event.send(serv) if max_size is None: max_size = DEFAULT_MAX_SIMULTANEOUS_REQUESTS pool = Pool(max_size=max_size) try: host, port = sock.getsockname() port = ':%s' % (port, ) if sock.is_secure: scheme = 'https' if port == ':443': port = '' else: scheme = 'http' if port == ':80': port = '' print "(%s) wsgi starting up on %s://%s%s/" % (os.getpid(), scheme, host, port) while True: try: try: client_socket = sock.accept() except socket.error, e: if e[0] != errno.EPIPE and e[0] != errno.EBADF: raise pool.execute_async(serv.process_request, client_socket) except KeyboardInterrupt: api.get_hub().remove_descriptor(sock.fileno()) print "wsgi exiting" break
def server(sock, site, log=None, environ=None, max_size=None, max_http_version=DEFAULT_MAX_HTTP_VERSION, protocol=HttpProtocol, server_event=None, minimum_chunk_size=None): serv = Server(sock, sock.getsockname(), site, log, environ=None, max_http_version=max_http_version, protocol=protocol, minimum_chunk_size=minimum_chunk_size) if server_event is not None: server_event.send(serv) if max_size is None: max_size = DEFAULT_MAX_SIMULTANEOUS_REQUESTS pool = Pool(max_size=max_size) try: host, port = sock.getsockname() port = ':%s' % (port, ) if sock.is_secure: scheme = 'https' if port == ':443': port = '' else: scheme = 'http' if port == ':80': port = '' print("(%s) wsgi starting up on %s://%s%s/" % (os.getpid(), scheme, host, port)) while True: try: try: client_socket = sock.accept() except socket.error as e: if e[0] != errno.EPIPE and e[0] != errno.EBADF: raise pool.execute_async(serv.process_request, client_socket) except KeyboardInterrupt: api.get_hub().remove_descriptor(sock.fileno()) print("wsgi exiting") break finally: try: sock.close() except socket.error as e: if e[0] != errno.EPIPE: raise
def test_contention(self): from greentest import saranwrap_test prox = saranwrap.wrap(saranwrap_test) pool = Pool(max_size=4) waiters = [] waiters.append(pool.execute(lambda: self.assertEqual(prox.one, 1))) waiters.append(pool.execute(lambda: self.assertEqual(prox.two, 2))) waiters.append(pool.execute(lambda: self.assertEqual(prox.three, 3))) for waiter in waiters: waiter.wait()
def CoroutinePool(*args, **kwargs): from eventlib.pool import Pool return Pool(*args, **kwargs)