Client tracing example emits deprecation warning #3964
Closed
Description
Long story short
Example of client tracing in the documentation emits a deprecation warning.
Expected behaviour
Execution without any deprecation warning.
Actual behaviour
$ python -Wd test.py
test.py:7: DeprecationWarning: client.loop property is deprecated
trace_config_ctx.start = session.loop.time()
test.py:11: DeprecationWarning: client.loop property is deprecated
elapsed = session.loop.time() - trace_config_ctx.start
Request took 0.2158021649811417
Steps to reproduce
The example is taken from https://docs.aiohttp.org/en/stable/client_advanced.html#client-tracing
import asyncio
import aiohttp
async def on_request_start(session, trace_config_ctx, params):
trace_config_ctx.start = session.loop.time()
async def on_request_end(session, trace_config_ctx, params):
elapsed = session.loop.time() - trace_config_ctx.start
print("Request took {}".format(elapsed))
async def run():
trace_config = aiohttp.TraceConfig()
trace_config.on_request_start.append(on_request_start)
trace_config.on_request_end.append(on_request_end)
async with aiohttp.ClientSession(trace_configs=[trace_config]) as client:
await client.get("http://example.com/some/redirect/")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()Your environment
Aiohttp as a client.
$ python -V
Python 3.6.8
$ pip freeze | grep aiohttp
aiohttp==3.5.4
Possible solutions
Should the session.loop not emit a deprecation warning? (a.k.a is this a bug?). Or should the example use asyncio.get_event_loop() instead?
Metadata
Assignees
Labels
No labels