I think this is documented poorly but basically when you did server =
StopableWSGIServer.create(...) the server is already running at that point.
The run() method is not necessary when using create(). It is only necessary
if you don't use the create() helper and directly instantiate a
StopableWsgiServer yourself.

You can see this in the code here
https://github.com/Pylons/webtest/blob/0b9d1a748e6c1436cdb1e6fd6c251d201a487aac/webtest/http.py#L117-L120

On Thu, Oct 1, 2015 at 9:38 AM, Alain Désilets <[email protected]>
wrote:

> I am working on some integration tests for a Pyramid app, and I want to
> run the under StopableWSGIServer, in the same process as the tests. The
> reason for this is that I want to get test coverage for both the tests and
> the app itself.
>
>
> But try as I may, it seems that StoppableWSGIServer.run() is blocking,
> which prevents the tests from ever running.
>
>
> Below is a small "hello world" script that illustrates the problem.
> Basically, the print statements that follow the call to run() are never
> printed. Also, when I load the 'hello' page in a browser, it displays
> properly, but I get the following exceptions in the server's console window:
>
>
>
> - Socket error
>
> - Unexpected exception when flushing
>
>
>
> Here is the code for the script. Am I misunderstanding how to use
> StopableWSGIServer? Maybe this is a Windows vs Unix thing (I am running
> this on Windows 7).
>
>
>
> I googled for StopableWSGIServer with the various exceptions and didn't
> find anything.
>
>
> Thx for your help.
>
>
> Alain
>
>
>
> ------ demoapp.py ---
>
> from pyramid.config import Configurator
>
> from pyramid.response import Response
>
> from webtest.http import StopableWSGIServer
>
>
>
> def hello_world(request):
>
>     return Response('Hello %(name)s!' % request.matchdict)
>
>
>
> def main():
>
>     """ This function returns a Pyramid WSGI application.
>
>     """
>
>     config = Configurator()
>
>     config.add_route('hello', '/hello/{name}')
>
>     config.add_view(hello_world, route_name='hello')
>
>     return config.make_wsgi_app()
>
>
>
> if __name__ == "__main__":
>
>     app = main()
>
>     port = 6543
>
>     host = 'localhost'
>
>     server = StopableWSGIServer.create(app, port=port, host=host)
>
>
>
>     server.run()
>
>
>
>     #
>
>     # Hum... somehow on windows, the run() call above is blocking and we
> never
>
>     # get to see the message printed by the rest of the script.
>
>     #
>
>     # Also, when I access
>
>     #
>
>     #   http://localhost:6543/hello/alain
>
>     #
>
>     # The page displays correctly in the web browser, but the server's
>
>     # console window shows this error message:
>
>     #
>
>     # Socket error
>
>     # Traceback (most recent call last):
>
>     #   File "C:\Python34\lib\site-packages\waitress\channel.py", line
> 166, in handle_read
>
>     #     data = self.recv(self.adj.recv_bytes)
>
>     #   File "C:\Python34\lib\asyncore.py", line 379, in recv
>
>     #     data = self.socket.recv(buffer_size)
>
>     # BlockingIOError: [WinError 10035] A non-blocking socket operation
> could not be completed immediately
>
>     #
>
>     # OR, other times I will get this message:
>
>     #
>
>     # Unexpected exception when flushing
>
>     # Traceback (most recent call last):
>
>     #   File "C:\Python34\lib\site-packages\waitress\channel.py", line
> 139, in handle_write
>
>     #     flush()
>
>     #   File "C:\Python34\lib\site-packages\waitress\channel.py", line
> 258, in _flush_some
>
>     #     outbuf.skip(num_sent, True)
>
>     #   File "C:\Python34\lib\site-packages\waitress\buffers.py", line
> 269, in skip
>
>     #     buf.skip(numbytes, allow_prune)
>
>     #   File "C:\Python34\lib\site-packages\waitress\buffers.py", line 77,
> in skip
>
>     #     numbytes, self.remain)
>
>     # ValueError: Can't skip 146 bytes in buffer of 0 bytes
>
>     #
>
>     print("Web server started on %s:%s" % (host, port))
>
>     input("Type any key to stop the server...")
>
>     print("Shutting down the server...")
>
>     server.shutdown()
>
>     print("Server stopped... May need to Ctrl-C to quit completelly.")
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to