MCPcopy
hub / github.com/aio-libs/aiohttp / run_aiohttp

Function run_aiohttp

benchmark/async.py:27–71  ·  view source on GitHub ↗
(host, port, barrier, profile)

Source from the content-addressed store, hash-verified

25
26
27def run_aiohttp(host, port, barrier, profile):
28
29 from aiohttp import web
30
31 @asyncio.coroutine
32 def test(request):
33 txt = 'Hello, ' + request.match_info['name']
34 return web.Response(text=txt)
35
36 @asyncio.coroutine
37 def prepare(request):
38 gc.collect()
39 return web.Response(text='OK')
40
41 @asyncio.coroutine
42 def stop(request):
43 loop.call_later(0.1, loop.stop)
44 return web.Response(text='OK')
45
46 @asyncio.coroutine
47 def init(loop):
48 app = web.Application(loop=loop)
49 app.router.add_route('GET', '/prepare', prepare)
50 app.router.add_route('GET', '/stop', stop)
51 app.router.add_route('GET', '/test/{name}', test)
52
53 handler = app.make_handler(keep_alive=15, timeout=None)
54 srv = yield from loop.create_server(handler, host, port)
55 return srv, app, handler
56
57 loop = asyncio.get_event_loop()
58 srv, app, handler = loop.run_until_complete(init(loop))
59 barrier.wait()
60
61 if profile:
62 profiler.enable()
63
64 loop.run_forever()
65 srv.close()
66 loop.run_until_complete(handler.finish_connections())
67 loop.run_until_complete(srv.wait_closed())
68 loop.close()
69
70 if profile:
71 profiler.disable()
72
73
74def run_tornado(host, port, barrier, profile):

Callers

nothing calls this directly

Calls 5

waitMethod · 0.80
finish_connectionsMethod · 0.80
wait_closedMethod · 0.80
initFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected