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
Remove explicit "loop" argument from EchoClientProtocol example #82359
Comments
The EchoClientProtocol example receives a "loop" argument, which is not used at all in the TCP example, and is used to create a future in the UDP example. In modern asyncio code the explicit loop arguments are no longer used since the loop can always be obtained with get_running_loop(). The proposed patch makes the UDP example consistent with the TCP one (by having the constructor accept the on_con_lost future) and removes the loop argument from both. |
Hrvoje, thanks for fixing this. Next time, please involve the people who originally wrote the code. They are both still active. If they made mistakes, it helps them to know about it. If they had a specific intent for the code example, it allows them to make sure the objectives are still being achieved. |
Thanks Hrvoje! |
Raymond, no problem; I guess I assumed that the authors are following the bug tracker (or have possibly moved on and are inactive). I also had reason to believe the change to be non-controversial, since it is in line with Yury's own recommendations, e.g. from his 2018 EuroPython presentation (slide 14): https://speakerdeck.com/1st1/asyncio-today-and-tomorrow In any case, I am happy that the pull request has been processed and accepted so quickly - thanks everyone for the great work! |
Raymond, sorry if I was so quick in applying. The PR doesn't fix a mistake, the code is still valid. At the time of the example creation explicit loop was safer, after Python 3.5.3 bugfx release the implicit loop became the idiomatic solution. We use the implicit loop everywhere, 3.8 raises DeprecationWarning for passing the loop into certain API calls. |
Yeah, the trend changed. Around Python 3.4, passing explicitly loop was preferred for best performances. Since that time, the code to get the current loop has been optimized, and the new trend is to make the loop implicit to make the code more readable. -- When I wrote the doc, self.loop.stop() was called explicitly: https://docs.python.org/3.5/library/asyncio-protocol.html#tcp-echo-client-protocol It seems like the example has been modified to add a new "on_con_lost" Future. -- Anyway, thanks Hrvoje Nikšić for your contribution ;-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: