Python PM2

0
9χλμ.

With PM2, rolling restarts, monitoring, checking logs and even deploying application has never been that simple

PM2 is a production-grade process manager that makes management of background process easy. In the Python world we could compare PM2 to Supervisord, but PM2 has some nifty features you might like.

With PM2, rolling restarts, monitoring, checking logs and even deploying application has never been that simple. We really value CLI UX, so PM2 is really simple to use and master.

PM2 has 5 years of history, more than 65 million downloads and has become one of the preferred way to run Node.js in production servers. Checkout the PM2 Github

In this article, you will learn how to use the process manager PM2 to manage Python application, because yes it can also manage Python application efficiently!

INSTALLING PM2

PM2 depends on Node.js. To install Node it’s pretty straightforward:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

To install Node.js on other platforms check Installing Node.js via package manager

GET PM2

Now to install PM2 type:

sudo npm install pm2 -g

To initialize PM2, just type one command:

pm2 ls

You should see a nice ASCII art giving you some of the PM2 key commands:

┌──────────┬────┬─────────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
└──────────┴────┴─────────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

Now that PM2 has been installed let’s start a Python application.

STARTING A PYTHON APP

Starting an application with PM2 is straightforward. It will auto discover the interpreter to run your application depending on the script extension. This can be configurable via the Ecosystem config file, as I will show you later on this article.

Let’s take this dumbly simple Python app and call it hello.py:

#!/usr/bin/python
import time

while 1:
    print("Start: %s" % time.ctime())
    time.sleep(1)

Now to start it:

pm2 start hello.py

You will then see the process started:

[PM2] Starting /home/florian/playground-python/hello.py in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬──────────┬──────────┐
│ App name │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem      │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼──────────┼──────────┤
│ hello    │ 0  │ fork │ 76055 │ online │ 0       │ 0s     │ 2%  │ 2.8 MB   │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴──────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Социальные проблемы
Мадам Клод. Madame Claude. (2021)
Париж, 1960-е. Мадам Клод возглавляет процветающий бизнес, связанный с проституцией, который дает...
από Nikolai Pokryshkin 2022-09-12 22:15:57 0 26χλμ.
Cooking
Only chefs know them: 9 simple tips to make food healthier
If you are thinking about how useful the food that you put on your plate at home is, then you...
από FWhoop Xelqua 2023-05-08 19:24:34 0 20χλμ.
Magazines and E-zines
Top 10 Magazines of the week
Frieze Frieze Magazine Website The respected British art magazine celebrated its 20th...
από FWhoop Xelqua 2023-07-06 20:29:53 0 20χλμ.
Military
The Evolution of Military Strategy: From Ancient Tactics to Modern Warfare
The Evolution of Military Strategy: From Ancient Tactics to Modern Warfare Introduction: The...
από Leonard Pokrovski 2024-06-10 22:58:14 0 20χλμ.
Телевидение
PUBLIKA Live TV. Телевидение на русском, молдавском и румынском.
Телевидение Молдавии на русском и молдавском языках. Новости, погода, политика, происшествия и...
από Nikolai Pokryshkin 2022-10-31 14:28:01 0 27χλμ.

BigMoney.VIP Powered by Hosting Pokrov