Supervisor - Running python script PYTHONPATH problem

I am using a 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 does not start. Here's 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 to get mymodule, but if I run twitter.py on my own, everything will work fine, it only throws this error when I run it through the supervisor.

I added mymodule in PYTHONPATH to my ~ / .profile file, for example:

 export PYTHONPATH=$PYTHONPATH:/home/ubuntu/lib 

Is there a reason why the script will work when launched through the terminal, but not when launched through the dispatcher? Any help would be appreciated.

+8
supervisord
source share
2 answers

Add the definition of PYTHONPATH to the environment directive in the superside configuration file. It should be in the [program:twitter_track] , for example:

 environment=PYTHONPATH=/home/ubuntu/lib/ 

This ensures that your python process sees the correct PYTHONPATH when the supervisor starts it.

+24
source share

Add PYTHONPATH definition on Wednesday:

 [program:twitter_track] command = python /home/ubuntu/services/twitter.py track environment=PYTHONPATH=/home/ubuntu/lib 
0
source share

All Articles