我试图了解如何使这个例子成为一个aiohttp.web.Application
实例,以便它可以使用这种模式:
def handler1(request):
...
def handler2(request):
...
app = web.Application()
app.router.add_route('GET', '/one', handler1)
app.router.add_route('GET', '/two', handler2)
让我的生活变得困难的是,我已经能够将我的应用程序实例带到 ChildProcess。init但无法弄清楚如何修改启动方法(我只保留了需要帮助修改的部分):
class ChildProcess:
def __init__(self, up_read, down_write, app, args, sock):
...
self.app = app
...
def start(self):
...
# how to leverage the app.router here????
# these few lines like aiohttp.web.run_app(app) code
# there must be a way to make this work together
f = loop.create_server(
lambda: HttpRequestHandler(debug=True, keep_alive=75),
sock=self.sock)
srv = loop.run_until_complete(f)