22

Two questions:

  • Is there a Python equivalent to forever.js to run a Python process in the background without requiring sudo?
  • Is it possible to use forever.js with Python? How about with a virtualenv?
1
  • forever start -c python server.py Dec 31, 2020 at 10:23

3 Answers 3

39

It is easy to use Python with forever.js:

forever start -c python python_script.py

To use it with virtualenv is a little bit more complicated, I did it using a bash script (call it python_virtualenv):

#!/bin/bash
# Script to run a Python file using the local virtualenv
source bin/activate
bin/python $@

Now use that script with forever:

forever start -c ./python_virtualenv python_script.py
2
  • 2
    I'd use the correct path to the virtualenv Python script instead: forever start -c bin/python python_script.py.
    – Martijn Pieters
    Oct 24, 2013 at 16:29
  • How to make a json file for this?
    – Ashish
    Jul 23, 2015 at 8:47
0

I was having problems executing a python script with custom logging paths, after trying I got to work with the next command:

 forever start -c python -l /tmp/forever.log -o /tmp/out.log -e /tmp/error.log python_script.py

Tell me if it worked for you

1
  • Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> BrokenPipeError: [Errno 32] Broken pipe
    – gtzinos
    Jul 7, 2022 at 14:59
0

Using python 3 with Flask to run with forever.js, here is my build process

python3 -m venv venv
source venv/bin/activate
sudo -H pip3 install -r requirements.txt
FLASK_APP=app.py forever start -c python3 app.py --port=5001

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.