Pylons / pyramid

Pyramid - A Python web framework
https://trypyramid.com/
Other
3.97k stars 887 forks source link

Simple Pyramid app stuck on start #3628

Closed pacioreklibor closed 4 years ago

pacioreklibor commented 4 years ago

Clear new VENV

Simple application from: Creating Your First Pyramid Application

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello World!')

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    server.serve_forever()

When I run it using cmd: python app.py it get stuck.

After Control-C this appear:

Traceback (most recent call last):
  File "C:\Users\lpaciorek\OneDrive - Vendavo, Inc\Dev\Pyramid\Tutorial\app.py", line 16, in <module>
    server.serve_forever()
  File "C:\Users\lpaciorek\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "C:\Users\lpaciorek\AppData\Local\Programs\Python\Python39\lib\selectors.py", line 324, in select
    r, w, _ = self._select(self._readers, self._writers, [], timeout)
  File "C:\Users\lpaciorek\AppData\Local\Programs\Python\Python39\lib\selectors.py", line 315, in _select
    r, w, x = select.select(r, w, w, timeout)
stevepiercy commented 4 years ago

That is expected. Did you visit the URL http://localhost:6543/ in a web browser after running the Python command? I just tried this on macOS 10.15/Python 3.9.0/Pyramid 1.10.4 without trouble and got the exact same output. Sorry I don't have Win 10 to test on, but my results are nearly identical to yours.

% $v/bin/python app.py
127.0.0.1 - - [06/Nov/2020 01:41:49] "GET / HTTP/1.1" 200 12
127.0.0.1 - - [06/Nov/2020 01:41:50] "GET /favicon.ico HTTP/1.1" 404 164
^CTraceback (most recent call last):
  File "/Users/stevepiercy/projects/_test/app.py", line 16, in <module>
    server.serve_forever()
  File "/Users/stevepiercy/.pyenv/versions/3.9.0/lib/python3.9/socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "/Users/stevepiercy/.pyenv/versions/3.9.0/lib/python3.9/selectors.py", line 416, in select
    fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt
pacioreklibor commented 4 years ago

Thank you Steve. I just moved from other frameworks - which printing when server start. It is not bug or issue.

stevepiercy commented 4 years ago

That's not Pyramid, but the web server wsgiref. If you use the cookiecutter instead, you will get something like:

Starting subprocess with file monitor
Starting server in PID 73732.
Serving on http://localhost:6543
Serving on http://localhost:6543

If you're just starting with Pyramid, I would recommend going through the Pyramid Quick Tutorial, then come back to the narrative documentation. That way you get an overview of Pyramid with jumping off points into the very detailed narrative documentation.