-
Notifications
You must be signed in to change notification settings - Fork 229
Fix the readme gRPC usage example #122
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
Fix the readme gRPC usage example #122
Conversation
- fix a syntax error - fix a usage error
- this lib targets >= 3.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you! Our documentation is essential for a good user experience, so this improvement is very welcome 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor suggestions.
README.md
Outdated
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) | |
if __name__ == '__main__': | |
asyncio.run(main()) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i specifically didn't use asyncio.run
(cause of second commit) as It is introduced into the standard library as of python 3.7, since this library targets >= 3.6 this method cannot be used without breaking in that older interpreter.
Moving the runtime into a entry point check, however, is a good idea.
Optimized imports, store RPC call result before printing Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
This reverts commit 2745953
* re-implement README gRPC client example to be a self-contained script - fix a syntax error - fix a usage error * asyncio.run() was added in 3.7 - this lib targets >= 3.6 * Apply suggestions from code review Optimized imports, store RPC call result before printing Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com> * add entry-point check to example Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
The sample gRPC client implementation in the readme had two defects in it which this PR corrects.
The first is a simple syntax error in the
async for
line, and should require no further explanation.The second is a library usage error relating to the application of
grpclib.client.Channel
.The issue stems from
grpclib.client.Channel
needing to be manually closed at the end of the session, which the readme example failed to do. This leads to runtime warnings when the channel object gets GC'ed.As discussed in slack, not calling
channel.close()
is a implementation error and is the primary motivation of this PR.Changes in tone:
I rewrote the client example to run from a script file instead of assuming a REPL, which I believe to be more realistic a use case.
The other examples in the README are, imho, sufficient to demonstrate the intended functionality.