本文整理匯總了Python中asyncio.AbstractServer方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.AbstractServer方法的具體用法?Python asyncio.AbstractServer怎麽用?Python asyncio.AbstractServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類asyncio
的用法示例。
在下文中一共展示了asyncio.AbstractServer方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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()
示例2: __init__
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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
示例3: start_manhole
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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
示例4: start_server
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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
示例5: __init__
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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]
示例6: test_webserver_is_created
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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)
示例7: __init__
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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]
示例8: __init__
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import AbstractServer [as 別名]
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)