-
-
Notifications
You must be signed in to change notification settings - Fork 99
cheroot.server: procedure serve() has detached from start()
#98
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
Codecov Report
@@ Coverage Diff @@
## master #98 +/- ##
==========================================
+ Coverage 66.05% 67.44% +1.38%
==========================================
Files 19 19
Lines 3067 3781 +714
==========================================
+ Hits 2026 2550 +524
- Misses 1041 1231 +190 |
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.
Without understanding the user's underlying complaint, the change this PR attempts to make seems perfectly reasonable.
I would make one request, though - don't use a boolean parameter to a function to select what that function does. Instead, just call the functions you need. i.e.:
def start(self):
self.prepare()
self.serve()
def prepare(self):
# do the prepThis simpler refactoring provides the necessary hook that prepares the server without starting, but also to start the server, but more clearly and simply.
…d from ``start()``
|
@jaraco I agree with your code suggestion. (I thought about it early, but at that time I was afraid doing it, cause it is more big change) I've just changed my branch to your suggestion. |
|
the example of using now is # -*- mode: python; coding: utf-8 -*-
from cheroot.wsgi import Server
import signal
import threading
def helloAAA_wsgi(environ, start_response):
start_response('200 OK', [('Content-type','text/plain;charset=utf-8')])
yield 'Hello world! #AAA\n'.encode()
def helloBBB_wsgi(environ, start_response):
start_response('200 OK', [('Content-type','text/plain;charset=utf-8')])
yield 'Hello world! #BBB\n'.encode()
def helloCCC_wsgi(environ, start_response):
start_response('200 OK', [('Content-type','text/plain;charset=utf-8')])
yield 'Hello world! #CCC\n'.encode()
def main():
signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGINT, signal.SIGTERM})
serverAAA = Server(('127.0.0.1', 8081), helloAAA_wsgi)
serverBBB = Server(('127.0.0.1', 8082), helloBBB_wsgi)
serverCCC = Server(('127.0.0.1', 8083), helloCCC_wsgi)
serverAAA.prepare()
serverBBB.prepare()
serverCCC.prepare()
print('*** all servers have started! ***')
t1 = threading.Thread(target=serverAAA.serve)
t2 = threading.Thread(target=serverBBB.serve)
t3 = threading.Thread(target=serverCCC.serve)
t1.start()
t2.start()
t3.start()
print('*** serving requests is in process... ***')
signal.sigwaitinfo({signal.SIGINT, signal.SIGTERM})
print('*** terminating... ***')
# now it is SAFE to invoke ``stop()`` here
serverAAA.stop()
serverBBB.stop()
serverCCC.stop()
t1.join()
t2.join()
t3.join()
print('*** gracefully terminated! ***')
if __name__ == '__main__':
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.
LGTM.
@polymorphm would you mind adding tests/docs as well?
|
@webknjaz > would you mind adding tests/docs as well? I added two tests, with hoping them are useful :-) . Is there documentation only in cheroot/cheroot/server.py header doc-string? |
|
@polymorphm you may create an |
cheroot/test/test_server.py
Outdated
| def test_prepare_makes_server_ready(): | ||
| """Check that prepare() makes the server ready, and stop() clears it.""" | ||
| httpserver = HTTPServer( | ||
| bind_addr=(ANY_INTERFACE_IPV6, EPHEMERAL_PORT), |
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 might be unstable in case of missing IPv6.
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.
you're right
|
I've added some words about starting and stopping a server and made links-to-functions "clickable". It looks ready enough in my humble opinion :-) . I apologize for delays from my side |
| if req.close_connection: | ||
| return | ||
| For running a server you can invoke :func:`start() <HTTPServer.start()>` (it |
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.
Have you tried rendering it? I think it's a broken reference.
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 rendered via
pip install '.[docs]' && sphinx-build docs docs/_build
it did this HTML:
<p>For running a server you can invoke <a class="reference internal" href="#cheroot.server.HTTPServer.start" title="cheroot.server.HTTPServer.start"><code class="xref py py-func docutils literal notranslate"><span class="pre">start()</span></code></a> (it
will run the server forever) or use invoking <a class="reference internal" href="#cheroot.server.HTTPServer.prepare" title="cheroot.server.HTTPServer.prepare"><code class="xref py py-func docutils literal notranslate"><span class="pre">prepare()</span></code></a> and <a class="reference internal" href="#cheroot.server.HTTPServer.serve" title="cheroot.server.HTTPServer.serve"><code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code></a> like this:</p>
where the reference is
<dl class="method">
<dt id="cheroot.server.HTTPServer.start">
<code class="descname">start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cheroot.server.HTTPServer.start" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the server forever.</p>
<p>It is shortcut for invoking <a class="reference internal" href="#cheroot.server.HTTPServer.prepare" title="cheroot.server.HTTPServer.prepare"><code class="xref py py-func docutils literal notranslate"><span class="pre">prepare()</span></code></a> then <a class="reference internal" href="#cheroot.server.HTTPServer.serve" title="cheroot.server.HTTPServer.serve"><code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code></a>.</p>
</dd></dl>
It looks correct for me.
may be I should use some other command for rendering? could you write it to me please?
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.
No, looks fine. It's just that normally you don't need to put braces there.
|
@polymorphm thanks! |
|
Testing under osx/3.7 env failed because of missing cc: @jaraco |
|
Upload successful: https://pypi.org/project/Cheroot/6.4.0/ |
#)it is release with issues #68 ("is there any right way to interrupt a started server?")
see my next simple example:
please, see my next another example:
Other information:
Checklist:
and description in grammatically correct, complete sentences
This change is