So we used to run our Pyramid server with Apache in production. But we are moving to Docker containerization for easier prod deployments etc, and we want to adhere to the philosophy of “one process per container”..so instead of running Apache in the container + 4 python procs, we just want 1 python proc.
So my question is – is there a way to run a Pyramid server in production directly? Without using WSGI+Apache?
My understanding is that pserve is for development only?
Create an application.py
file and fill it with the following contents:
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('<h1>Hello world!</h1>')
if __name__ == '__main__':
config = Configurator()
config.add_view(hello_world)
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
Will the above work as a production-grade server?
3
Answers
The latest official recommendation is one concern per container. From the Docker docs (emphasis my own):
In your case, your web application server is a single concern. Running Apache+WSGI is totally fine. Don’t worry about the processes—That’s Apache’s job.
For a better understanding of the “one concern” rule, this post is a good overview of what problems its trying to solve.
You can use Waitress, which, according to their documentation, is
Waitress is a part of the Pylons Project just like Pyramid is.
It looks like Bjoern is a solid choice when it comes to running Python directly, where the Python server has WSGI bindings:
https://www.appdynamics.com/blog/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/
https://github.com/jonashaag/bjoern