pythondjangopm2

Use pm2 with Django


I have just changed from Express with NodeJS to Django with Python. The only thing I miss about NodeJS was the wonderful process manager pm2. Can I use pm2 with Django?


Solution

  • This is indeed a very broad question, but I would like to my personal point of view because I use both frameworks in my projects.

    express(nodejs) to django(python)

    Express and Django are both web frameworks, but Node and Python do not fall in the same category. You could say JS and Python better. Node is a runtime environment for JS, so a tool like pm2 effectively manages Node processes.

    For web projects based on Python you need to select a way (interface) to serve them. Common possibilities are CGI and WSGI.

    I cannot talk about flask, but Django recommended way is WSGI. There are several options including mod_wsgi, uwsgi and gunicorn. Any tool to control their processes depends on which you choose.

    In this sense, this is one level of complexity more. I would recommend you to explore all of them, read about them, possibly test them and pick the one that is best for your needs.

    I personally prefer uwsgi because I find it very fast, especially under load, and sometimes mod_wsgi if the host is so configured (doh). UWSGI has an excellent stats solution.

    Not to mention that there are many tools for whatever server you end up using with WSGI.

    Having said that, will you will not easily reach the response times of node for simple requests. But when in node things get complicated (too many callbacks, too many queries etc) then times get pretty similar. On the other hand, as soon as you get a grasp on Django, you will be amazed on how little time you need to write and maintain code comparing to the callback hell and completely immature data layer of Node.