Python asyncio.AbstractServer() Examples
The following are 8
code examples of asyncio.AbstractServer().
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
asyncio
, or try the search function
.
Example #1
Source File: session.py From lbry-sdk with MIT License | 6 votes |
def __init__(self, env: 'Env', db: LBRYLevelDB, bp: LBRYBlockProcessor, daemon: 'Daemon', mempool: 'MemPool', shutdown_event: asyncio.Event): env.max_send = max(350000, env.max_send) self.env = env self.db = db self.bp = bp self.daemon = daemon self.mempool = mempool self.peer_mgr = PeerManager(env, db) self.shutdown_event = shutdown_event self.logger = util.class_logger(__name__, self.__class__.__name__) self.servers: typing.Dict[str, asyncio.AbstractServer] = {} self.sessions: typing.Set['SessionBase'] = set() self.cur_group = SessionGroup(0) self.txs_sent = 0 self.start_time = time.time() self.history_cache = self.bp.history_cache self.notified_height: typing.Optional[int] = None # Cache some idea of room to avoid recounting on each subscription self.subs_room = 0 self.session_event = Event()
Example #2
Source File: distribution.py From Pyrlang with Apache License 2.0 | 5 votes |
def __init__(self, node_name: str) -> None: self.node_name_ = node_name """ Node name, a string. """ self.creation_ = 0 """ Creation id used in pid generation. EPMD gives creation id to newly connected nodes. """ self.in_port_ = None # type: [None, int] self.in_srv_ = None # type: [None, asyncio.AbstractServer] self.epmd_ = EPMDClient() self.n_connect_tries_ = 5
Example #3
Source File: manhole.py From mautrix-python with Mozilla Public License 2.0 | 5 votes |
def start_manhole(path: str, banner: str = "", namespace: Optional[Dict[str, Any]] = None, loop: asyncio.AbstractEventLoop = None, whitelist: Set[int] = None, ) -> Tuple[asyncio.AbstractServer, Callable[[], None]]: """ Starts a manhole server on a given UNIX address. Args: path: The path to create the UNIX socket at. banner: The banner to show when clients connect. namespace: The globals to provide to connected clients. loop: The asyncio event loop to use. whitelist: List of user IDs to allow connecting. """ if not SO_PEERCRED: raise ValueError("SO_PEERCRED is not supported on this platform") loop = loop or asyncio.get_event_loop() factory = InterpreterFactory(namespace=namespace, banner=banner, interpreter_class=AsyncInterpreter, loop=loop, whitelist=whitelist) server = await asyncio.start_unix_server(factory, path=path, loop=loop) os.chmod(path, 0o666) def stop(): for client in factory.clients: client.close() server.close() return server, stop
Example #4
Source File: server.py From chia-blockchain with Apache License 2.0 | 5 votes |
def start_server( self: "ChiaServer", on_connect: OnConnectFunc = None ) -> asyncio.AbstractServer: """ Launches a listening server on host and port specified, to connect to NodeType nodes. On each connection, the on_connect asynchronous generator will be called, and responses will be sent. Whenever a new TCP connection is made, a new srwt tuple is sent through the pipeline. """ require_cert = self._local_type not in (NodeType.FULL_NODE, NodeType.INTRODUCER) ssl_context = ssl_context_for_server( self.root_path, self.config, require_cert=require_cert ) server, aiter = await start_server_aiter( self._port, host=None, reuse_address=True, ssl=ssl_context ) def add_connection_type( srw: Tuple[asyncio.StreamReader, asyncio.StreamWriter] ) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter, OnConnectFunc]: ssl_object = srw[1].get_extra_info(name="ssl_object") peer_cert = ssl_object.getpeercert() self.log.info(f"Client authed as {peer_cert}") return (srw[0], srw[1], on_connect) srwt_aiter = map_aiter(add_connection_type, aiter) # Push aiters that come from the server into the pipeline if not self._srwt_aiter.is_stopped(): self._srwt_aiter.push(srwt_aiter) self.log.info(f"Server started on port {self._port}") return server
Example #5
Source File: web_runner.py From Galaxy_Plugin_Bethesda with MIT License | 5 votes |
def __init__(self, runner: 'BaseRunner', *, shutdown_timeout: float=60.0, ssl_context: Optional[SSLContext]=None, backlog: int=128) -> None: if runner.server is None: raise RuntimeError("Call runner.setup() before making a site") self._runner = runner self._shutdown_timeout = shutdown_timeout self._ssl_context = ssl_context self._backlog = backlog self._server = None # type: Optional[asyncio.AbstractServer]
Example #6
Source File: test_utils.py From event-driven-microservice with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_webserver_is_created(event_loop): async def dummy_view(request): await asyncio.sleep(1, loop=event_loop) srv = await utils.webserver(event_loop, dummy_view, '127.0.0.1', 8080) assert isinstance(srv, asyncio.AbstractServer)
Example #7
Source File: tcp_server.py From agents-aea with Apache License 2.0 | 5 votes |
def __init__(self, configuration: ConnectionConfig, **kwargs): """ Initialize a TCP server connection. :param configuration: the configuration object. """ address = cast(str, configuration.config.get("address")) port = cast(int, configuration.config.get("port")) assert address is not None and port is not None, "address and port must be set!" super().__init__(address, port, configuration=configuration, **kwargs) self._server = None # type: Optional[AbstractServer] self.connections = {} # type: Dict[str, Tuple[StreamReader, StreamWriter]] self._read_tasks_to_address = dict() # type: Dict[Future, Address]
Example #8
Source File: server.py From grpclib with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init__( self, handlers: Collection['IServable'], *, loop: Optional[asyncio.AbstractEventLoop] = None, codec: Optional[CodecBase] = None, status_details_codec: Optional[StatusDetailsCodecBase] = None, config: Optional[Configuration] = None, ) -> None: """ :param handlers: list of handlers :param loop: (deprecated) asyncio-compatible event loop :param codec: instance of a codec to encode and decode messages, if omitted ``ProtoCodec`` is used by default :param status_details_codec: instance of a status details codec to encode error details in a trailing metadata, if omitted ``ProtoStatusDetailsCodec`` is used by default """ if loop: warnings.warn("The loop argument is deprecated and scheduled " "for removal in grpclib 0.4", DeprecationWarning, stacklevel=2) mapping: Dict[str, 'const.Handler'] = {} for handler in handlers: mapping.update(handler.__mapping__()) self._mapping = mapping self._loop = loop or asyncio.get_event_loop() if codec is None: codec = ProtoCodec() if status_details_codec is None and _googleapis_available(): status_details_codec = ProtoStatusDetailsCodec() self._codec = codec self._status_details_codec = status_details_codec self._h2_config = h2.config.H2Configuration( client_side=False, header_encoding='ascii', validate_inbound_headers=False, validate_outbound_headers=False, normalize_inbound_headers=False, normalize_outbound_headers=False, ) config = Configuration() if config is None else config self._config = config.__for_server__() self._server: Optional[asyncio.AbstractServer] = None self._handlers: Set[Handler] = set() self.__dispatch__ = _DispatchServerEvents() _servers.add(self)