Discuss / Python / app.make_handler()这个方法用不了,改用APPrunner

app.make_handler()这个方法用不了,改用APPrunner

Topic source

咕咕111111

#1 Created at ... [Delete] [Delete and Lock User]
app.make_handler()这个方法用不了,改用APPrunner,虽然我没看懂,但是官方替换是这样得,有大神解析嘛,代码能正常运行。
import asynciofrom aiohttp import webasync def index(request):    await asyncio.sleep(0.5)    return web.Response(body=b'<h1>Index</h1>', content_type='text/html', charset='utf-8')async def hello(request):    await asyncio.sleep(0.5)    text = '<h1>hello, %s!</h1>' % request.match_info['name']    return web.Response(body=text.encode('utf-8'))async def init():    app = web.Application()    app.router.add_get('/', index)    app.router.add_get('/hello/{name}', hello)    runner = web.AppRunner(app)  # app.make_handler()这个方法用不了,改用APPrunner,虽然我没看懂,但是官方替换是这样得    await runner.setup()    site = web.TCPSite(runner, '127.0.0.1', 8000)    await site.start()    print('Server started at http://127.0.0.1:8000...')    return siteloop = asyncio.get_event_loop()loop.run_until_complete(init())loop.run_forever()

  • 1

Reply