I am using supervisor to run a python script:
[program:twitter_track]
autorestart = true
numprocs = 1
autostart = false
redirect_stderr = True
stopwaitsecs = 1
startsecs = 1
priority = 99
command = python /home/ubuntu/services/twitter.py track
startretries = 3
stdout_logfile = /home/ubuntu/logs/twitter_track.log
But the process fails to start. Here is what the error log says:
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
from mymodule.twitter.stream import TwitterStream
ImportError: No module named mymodule.twitter.stream
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
It seems that obtain mymodule, but if I run twitter.py on it's own, everything works fine, it only throws this error when I run it through supervisor.
I added mymodule to the PYTHONPATH in my ~/.profile file like so:
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/lib
Is there any reason why the script would work when run through terminal but not when run through supervisor? Any help would be appreciated.
Add the PYTHONPATH
definition to the environment
directive in the supervisord configuration file. It should go under your [program:twitter_track]
section, like so:
environment=PYTHONPATH=/home/ubuntu/lib/
This will ensure that that your python process sees the proper PYTHONPATH
when supervisord starts it.