Python asyncio 模块,Server() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用asyncio.Server()

项目:urban-journey    作者:urbanjourney    | 项目源码 | 文件源码
def start_server(self):
        """
        Starts the listening server.

        :return: Server object if successful, otherwise None.
        :rtype: asyncio.Server
        """

        nlog.info("Creating server listing on '{}:{}'...".format(self.host, self.port))
        try:
            self.server = await asyncio.start_server(self.create_connection,
                                                     self.host,
                                                     self.port)
            nlog.info(self.log_prefix + "Success created server listing on '{}:{}'...".format(self.host, self.port))

        except:
            self.startup_exception_info = sys.exc_info()
            nlog.exception(self.log_prefix + "Error opening server listening on '{}:{}'...".format(self.host, self.port))

        self.started_semaphore.release()
        return self.server
项目:big-buck-asyncio    作者:qntln    | 项目源码 | 文件源码
def start(self) -> None:
        '''
        Start socket server which will stream movie
        '''
        self._logger.info('Server starting at = %s:%d', self.host, self.port)
        self._server = await asyncio.start_server(self._handle_client, self.host, self.port)
项目:socketshark    作者:closeio    | 项目源码 | 文件源码
def close(self):
        """
        Called by SocketShark to indicate that the backend should stop
        accepting connections.
        """
        # Stop the underlying asyncio.Server from accepting new connections.
        if self.server:
            self.server.server.close()
项目:urban-journey    作者:urbanjourney    | 项目源码 | 文件源码
def __init__(self, host, port, connections, loop=None):
        self.host = host  #: Listening host
        self.port = port  #: Listening port
        self.loop = loop or event_loop.get()  #: Event loop onto which the listener is running.
        self.server = None  #: class:`asyncio.Server` instance used by the listener.
        self.connections = connections  #: Dictionary containing all connections.

        asyncio.run_coroutine_threadsafe(self.start_server(), self.loop)

        self.started_semaphore = asyncio.Semaphore(0)

        self.startup_exception_info = None
项目:py-evm    作者:ethereum    | 项目源码 | 文件源码
def start(path, chain=None, loop=None):
    '''
    :returns: initialized server
    :rtype: asyncio.Server
    '''
    if loop is None:
        loop = asyncio.get_event_loop()
    rpc = RPCServer(chain)
    server = loop.run_until_complete(asyncio.start_unix_server(
        connection_handler(rpc.execute),
        path,
        loop=loop,
        limit=MAXIMUM_REQUEST_BYTES,
    ))
    return server
项目:py-evm    作者:ethereum    | 项目源码 | 文件源码
def run_until_interrupt(server, loop=None):
    logger = logging.getLogger('evm.rpc.ipc')
    if loop is None:
        loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.debug('Server closed with Keyboard Interrupt')
    finally:
        loop.close()
项目:big-buck-asyncio    作者:qntln    | 项目源码 | 文件源码
def __init__(self, host: str, port: int, filename):
        self._logger = logging.getLogger(self.__class__.__name__)
        self.host = host
        self.port = port
        self.filename = filename

        self._server = None # type: asyncio.Server
        self._sessions = {}
项目:big-buck-asyncio    作者:qntln    | 项目源码 | 文件源码
def stop(self) -> None:
        '''
        Stop server and all sessions
        '''
        self._logger.info('Server stopping')

        self._server.close()
        await self._server.wait_closed()

        # Because dict cannot be changed during iteration
        # we have to convert keys to list
        for session_id in list(self._sessions.keys()):
            self._logger.info('Terminating session = %s', session_id)
            await self._killSession(session_id)
项目:MoMMI    作者:PJB3005    | 项目源码 | 文件源码
def __init__(self):
        self.server: asyncio.Server = None
        self.clients: Dict[asyncio.Task, Tuple[asyncio.StreamReader, asyncio.StreamWriter]] = {}