I started to write pyramid applications 3 weeks ago, as a python and pyramid novice. Now the application goes to production. In the development process, many errors and problems happened to the application, although the pyramid documentation is very good, some latest changes are not included in the reference document.
I wrote down the common problems I came across , and the solution I chose against the problem here.
1. How to install pyramid?
For help getting Pyramid set up, try the official install guide.
Also you may be interested at my pyramid installation guide.
2. Is there a quick start?
Yes, there is. To get the feel of how a Pyramid web application is created, go to the single file tasks tutorial page on the official site.
But be careful, the single file application is just for learning. It is single threaded which is not suitable for most production deployment. And it is not good for maintenance when all content in a single file.
3. How could I create a project for production deployment?
A scaffold project could be created for production deployment. A scaffold project means a template project. You can create project from scaffold. See the outdated official wiki tutorial for a general guide, the tutorial is for pyramid 1.2 which is different from 1.3. For current pyramid 1.3, you should read this document: Pyramid documentation 1.3 . I’ve written A quick start for python pyramid for quick reference of pyramid project creation.
4.When I create project by the wiki tutorial of Pyramid and run paster create xxx, it shows command not found?
Paster may not be installed. And if you are using pyraid 1.3 paster is not needed any more, see official Pyramid documentation 1.3 for detail.
5. The wiki tutorial said run “paster serve development.ini” to start pyramid. But paster does not exist.
Paster serve is replaced by pserve in pyramid 1.3.
$ ../bin/pserve development.ini
6. When I run “pserve development.ini” to start pyramid by Pyramid documentation 1.3. It shows error: “pkg_resources.DistributionNotFound: waitress”.
In pyramid 1.3a7, a new dependency waitress is introduced. You can install the packed by easy_install or pip: pip install waitress
7.When I start pyramid by pserve, it allows visiting of only 1 concurrent user.
pserve is single threaded, and is for development purpose. For multithreaded production deployment, you should take one of these wsgi server.
8. Is there a simple way to deploy pyramid as multithreaded application?
Yes, you can Gunicorn to deploy pyramid as multithreaded application.
Firstly install gunicorn and eventlet:
$easy_install gunicorn eventlet
Then create file runapp.py as the following lines:
from paste.deploy import loadapp application = loadapp('config:production.ini', relative_to='.')
Then run the following command to start pyramid as multithreaded application:
$gunicorn --workers=2 --worker-class=eventlet --bind 127.0.0.1:80 runapp
the worker-class means to start gunicorn in async mode(multi threaded).
And for single threaded deployment, you can easily run Gunicorn with `pserve production.ini` if you’ve been using with Waitress. Just replace the [server:main] section within production.ini as shown in the document: http://gunicorn.org/run.html#paster-serve
Sorry, the comment form is closed at this time.