aio异步框架的检查孔服务器
aio.manhole.server的Python项目详细描述
用于aio异步框架的检查孔服务器
安装
需要python>;=3.4
安装时使用:
pip install aio.manhole.server
快速启动-检修孔服务器
将以下内容保存到文件“manhain.conf”
[server/my_manhole_server]factory=aio.manhole.server.factoryport=7373
使用aio run命令运行
aio run -c manhole.conf
现在您应该可以远程登录到端口7373上正在运行的服务器
aio.manhain.server用法
配置
允许创建检修孔配置
>>> config = """ ... [aio] ... log_level = ERROR ... ... [server/server_name] ... factory = aio.manhole.server.factory ... port = 7373 ... ... """
>>> import sys >>> import io >>> import aiomanhole
>>> import aio.testing >>> import aio.app >>> from aio.app.runner import runner
当我们运行检修孔服务器时,可以从aio.app.servers将其访问为“server_name”
>>> @aio.testing.run_forever(sleep=1) ... def run_manhole_server(config): ... yield from runner(['run'], config_string=config) ... ... def call_manhole(): ... print(aio.app.servers["server_name"]) ... aio.app.clear() ... ... return call_manhole
>>> run_manhole_server(config) <Server sockets=[<socket.socket ...laddr=('0.0.0.0', 7373)...>
让我们尝试调用检修孔服务器
>>> import asyncio >>> import telnetlib3
>>> @aio.testing.run_forever(sleep=1) ... def run_manhole_server(config): ... yield from runner(['run'], config_string=config) ... ... class TestTelnetClient(telnetlib3.TelnetClient): ... ... def data_received(self, data): ... print(data) ... ... def call_manhole(): ... loop = asyncio.get_event_loop() ... transport, protocol = yield from loop.create_connection( ... TestTelnetClient, "127.0.0.1", 7373) ... aio.app.clear() ... ... return call_manhole
>>> run_manhole_server(config) b'hello...\n>>> '