-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-112020: socketserver: Add an example for keeping the connection open #112054
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
Conversation
documentation - an example where TCP handler can handle many requests over the same connection,
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 seems reasonable but socketserver
isn't my area of expertise.
A
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 am not sure that a new example is needed. And it may be not enough, taking into account that the client code only calls a single sendall()
, and that there are no examples for repeated readline()
or for UDP sockets.
We can simply add that recv()
and readline()
can be called repeatedly, until tehy return an empty bytes object.
Doc/library/socketserver.rst
Outdated
@@ -528,6 +528,24 @@ The difference is that the ``readline()`` call in the second handler will call | |||
single ``recv()`` call in the first handler will just return what has been sent |
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.
In the line above add "or ``recv()``
returns an empty bytes object" after "until it encounters a newline character"
Co-authored-by: Serhiy Storchaka <[email protected]>
Hi, Please check my new commit. It uses Handling a single request is a special case of handling multiple requests, i.e., while supporting multiple requests, you also support a single request. This also means that the existing user examples are still compatible with the server examples. |
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.
Guys, please check this change. Here the existing handle
methods were extended to support one or more requests under the same connection. I think it looks elegant and clear now.
closing in favor of #129741 which modernizes the examples. we don't need to expand these further, showing handling multiple "requests" per handle call is not needed as that isn't the point of these examples which are merely about demonstrating handle being invoked per connection and how to interact with the socket from there. |
documentation - an example where TCP handler can handle many requests over the same connection, which is an undocumented important use case,
📚 Documentation preview 📚: https://cpython-previews--112054.org.readthedocs.build/