在Python中使用forever.js

rob*_*rit 17 python forever

两个问题:

  • 有没有Python等效于forever.js在后台运行Python进程而不需要sudo?
  • 可以在Python中使用forever.js吗?用virtualenv怎么样?

rob*_*rit 34

使用forever.js很容易使用Python:

forever start -c python python_script.py
Run Code Online (Sandbox Code Playgroud)

要将它与virtualenv一起使用有点复杂,我使用bash脚本(调用它python_virtualenv)来做到这一点:

#!/bin/bash
# Script to run a Python file using the local virtualenv
source bin/activate
bin/python $@
Run Code Online (Sandbox Code Playgroud)

现在永远使用该脚本:

forever start -c ./python_virtualenv python_script.py
Run Code Online (Sandbox Code Playgroud)

  • 我将使用virtualenv Python脚本的正确路径:`forever start -c bin/python python_script.py`. (2认同)