15

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.

3 Answers 3

35

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Add the PYTHONPATH definition to the environment:

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

Comments

0

@Darren Griffith give right solution. But if we see off docs http://supervisord.org/configuration.html#program-x-section-settings -> environment We wee, that it says

A list of key/value pairs in the form KEY="val",KEY2="val2"

So you need use a quotes ""

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.