Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client tracing example emits deprecation warning #3964

Closed
jcugat opened this issue Aug 7, 2019 · 3 comments

Comments

@jcugat
Copy link
Contributor

commented Aug 7, 2019

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?

@asvetlov

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

The second: use asyncio.get_event_loop() or even better asyncio.get_running_loop()

@jcugat

This comment has been minimized.

Copy link
Contributor Author

commented Aug 7, 2019

Got it, will open a PR fixing the documentation then.

@asvetlov

This comment has been minimized.

Copy link
Member

commented Aug 8, 2019

Fixed by #3965

@asvetlov asvetlov closed this Aug 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.