Skip to content

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

Merged

Conversation

theunkn0wn1
Copy link
Contributor

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.

boukeversteegh
boukeversteegh previously approved these changes Jul 20, 2020
Copy link
Collaborator

@boukeversteegh boukeversteegh left a 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 👍

Copy link
Collaborator

@abn abn left a 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
Comment on lines 172 to 174
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
if __name__ == '__main__':
asyncio.run(main())

Copy link
Contributor Author

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>
Gobot1234 added a commit to Gobot1234/python-betterproto that referenced this pull request Jul 21, 2020
@boukeversteegh boukeversteegh merged commit 2745953 into danielgtaylor:master Jul 25, 2020
@theunkn0wn1 theunkn0wn1 deleted the docs/fix_usage_examples branch July 25, 2020 18:44
Gobot1234 added a commit to Gobot1234/python-betterproto that referenced this pull request Jul 27, 2020
Gobot1234 added a commit to Gobot1234/python-betterproto that referenced this pull request Aug 6, 2020
Gobot1234 pushed a commit to Gobot1234/python-betterproto that referenced this pull request Aug 24, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants