pythontwistedgod

Unable to start python process using God


Im using God (godrb.com) to monitor a twisted framework based application process. In my god file (start_my_app.god) i have

God.watch do |w|
  w.name='my_app'
  w.start='twistd -y /home/joes/my_app.tac --pidfile /home/joes/my_app.pid'
  w.log='/home/joes/my_app.log'
  w.keepalive
end

In my application directory is a file called node.py containing the NodeQS class,and in the my_app.tac file im doing

from node import NodeQS

When i try to start the application using

god -c start_my_app.god -D

I see the following error in my application log

exceptions.ImportError: No module named node

I have added /home/joes/my_app to PYTHONPATH, but i still see this error when i run the twistd command using god.

The above twistd command works if i run it directly

Why is trying to run the same command from god giving me an import error ?


Solution

  • When you run a Python script with its full path, the PATHONPATH is set to the current working directory. This path is then used as the base to import the packages and modules.

    To make that the PYTHONPATH reflects your project directory, you cd there first. You can add the command to do so to the .start value:

    God.watch do |w|
      w.name='my_app'
      w.start='cd /home/joes; twistd -y /home/joes/my_app.tac --pidfile /home/joes/my_app.pid'
      w.log='/home/joes/my_app.log'
      w.keepalive
    end