我想了解以下底漆:aiohttp拉姆達在loop.start_server()方法
if __name__ == '__main__':
loop = asyncio.get_event_loop()
f = loop.create_server(
lambda: HttpRequestHandler(debug=True, keep_alive=75),
'0.0.0.0', '8080')
srv = loop.run_until_complete(f)
print('serving on', srv.sockets[0].getsockname())
try:
loop.run_forever()
except KeyboardInterrupt:
pass
爲什麼在asyncio.create_server方法拉姆達nottation?從asyncio文檔中,此方法接受類/函數作爲入口點。 HttpRequestHandler的。如果其attemt啓動類,並通過初始化實例循環,那麼即時通訊完全喪失,因爲我有奇怪behavion,初始化方法調用每一個請求:
class HttpRequestHandler(aiohttp.server.ServerHttpProtocol):
def __init__(self):
print(id(self))