How to run a python script like pm2 for nodejs How to run a python script like pm2 for nodejs python python

How to run a python script like pm2 for nodejs


You can actually run python scripts from within pm2:

pm2 start echo.py

If the script ends in a .py suffix it will use a python interpreter by default. If your filename doesn't end in .py you can do:

pm2 start echo --interpreter=python

I've found you have to be a little bit careful which python you are using, especially if you are using a virtualenv python with a different version to the 'default' python on your machine.


PM2 is enough, it will run interpreter by suffix:

{  ".sh": "bash",  ".py": "python",  ".rb": "ruby",  ".coffee" : "coffee",  ".php": "php",  ".pl" : "perl",  ".js" : "node"}


I created a echosystem file ecosystem.config.json

{    "apps": [{        "name": "app_name",        "script": "/the/app/path/my_app.py",        "args": ["-c", "my_config.prod.json"],        "instances": "1",        "wait_ready": true,        "autorestart": false,        "max_restarts": 5,        "interpreter" : "/path/to/venv/bin/python",    }]}

Run the pm2 service:

$ pm2 start ecosystem.config.json$ pm2 -v3.2.8