-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-36889: Document Stream class and add docstrings #14488 8000
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
bpo-36889: Document Stream class and add docstrings #14488
Conversation
Doc/library/asyncio-stream.rst
Outdated
.. coroutinemethod:: start_tls(sslcontext, *, server_hostname=None, \ | ||
ssl_handshake_timeout=None) | ||
|
||
Calls :meth:`Stream.drain()` and rest of the arguments are passed directly to |
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'd actually elaborate a bit on this method - why we have it, ideally, with an example.
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 have added a sentence over upgrading the TLS. I have also added similar sentence around sendfile
above. I couldn't come up with a useful example than calling connect
and then calling start_tls
to upgrade SSL in next statement. If there is a more practical one please add in.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
the high watermark, *drain()* blocks until the size of the | ||
buffer is drained down to the low watermark and writing can | ||
be resumed. When there is nothing to wait for, the :meth:`drain` | ||
returns immediately. |
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.
This is a bit more subtle. drain()
is only needed when you do a few stream.write()
calls. When you have only one stream.write()
you can just say await stream.write()
and not bother with drain()
. @asvetlov am I right?
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.
From my perspective, people always should use await stream.write()
form and never drain()
explicitly. There is no reason for late buffer overrun detection (and draining) if it can be done earlier.
The only reason why the method exists is backward compatibility for subprocess stdin/stdout/stderr pipes usage.
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 think we should reflect it in docs but sorry, I cannot propose exact wording.
Doc/library/asyncio-stream.rst
Outdated
.. coroutinemethod:: start_tls(sslcontext, *, server_hostname=None, \ | ||
ssl_handshake_timeout=None) | ||
|
||
Calls :meth:`Stream.drain()` to write to the connection and uses :meth:`loop.start_tls` |
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.
The same as for sendfile
: the method upgrades a connection to TLS encrypted one.
…hod and a coroutine.
I have pushed the changes to make sure
|
The interesting part is that multiple sync writes and single drain after doesn't help with buffering. Instead, it may consume more memory then expected. asyncio streams already have low and high watermarks for write buffer size control. If kernel write buffer is full the data is collected in asyncio internal write buffer. If the internal buffer size is greater than high watermark the writing is paused until the size of the buffer doesn't fall to less than the low watermark. After that write is resumed and keeps resumed until the high watermark is reached again. So, data is effectively buffered even if I doubt if we need to document it here, in a method reference. Maybe a separate asyncio section about buffering makes sense? |
Andrew, reading all of this makes me think about soft-deprecating non-await |
@1st1 I told you at US PyCon that non-awaitable methods are useless and should be deprecated eventually. You had doubts, so we decided to support both. I totally agree with the deprecation strategy. Does soft-deprecation means @1st1 what do you prefer? |
I'd do it in a very soft way in 3.8/3.9; basically we just warn users that they are deprecated in the docs and that's it. |
Ok, I agree with any decision. Sorry for the endless list of notes. Writing a new stream API took me weeks, documenting it takes a long as well. |
Added deprecated notes to No problem, I got to know better about the API while documentation and also closed some old and outdated issues related to Streams on the tracker with the PR. Appreciate your help on word formation and care to perfect user facing documentation. |
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 like the current text, looks good.
The last nitpick: please provide an order to Stream methods.
I think alphabetical sorting is better than the current grouping.
Good, done. The current order is alphabetic sort as below with attribute mode at first
|
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.
Well done!
Thank you very much!
@1st1 please review again. The PR is ready for merging from my perspective |
@tirkarthi: Status check is done, and it's a success ✅ . |
Thanks @tirkarthi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
I'm having trouble backporting to |
Thank you very much Andrew and Yury. I can create a separate PR if there are additional improvements. |
Oops. Sorry, @1st1 Anyway, please feel free to express your objection if any, @tirkarthi and I can fix them in the following PR quickly. |
Thanks @tirkarthi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
GH-16087 is a backport of this pull request to the 3.8 branch. |
* This just copies the docs from `StreamWriter` and `StreamReader`. * Add docstring for asyncio functions. https://bugs.python.org/issue36889 Automerge-Triggered-By: @asvetlov (cherry picked from commit d31b315) Co-authored-by: Xtreak <tir.karthi@gmail.com>
StreamWriter
andStreamReader
.https://bugs.python.org/issue36889
Automerge-Triggered-By: @asvetlov