0

I'm trying to come up with a workaround for this problem.

I'm deploying an application with Chef, and currently there is no PYTHONPATH set. This is fine for Django, which sets its own paths:

$ cat bin/django
#!/usr/bin/python

import sys
sys.path[0:0] = [
    '/opt/mytardis/releases/2737f42a91cd1b5d0a4b4c4609550fc586e351ab/eggs/nose-1.1.2-py2.7.egg',
    '/opt/mytardis/releases/2737f42a91cd1b5d0a4b4c4609550fc586e351ab/eggs/coverage-3.4-py2.7-linux-x86_64.egg',
    '/opt/mytardis/releases/2737f42a91cd1b5d0a4b4c4609550fc586e351ab/eggs/django_nose-1.1-py2.7.egg',
...

However, Celery launches 'python' processes directly, and fails because it can't find modules. In summary:

$ python -c from billiard.forking import main
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named billiard.forking

$ bin/django shell
>>> from billiard.forking import main
>>>

So I need to convert the list of paths set up in the Django script into a PYTHONPATH available to Python. And this conversion needs to be scriptable (because it's Chef).

So far I can only think of using Awk to munge the script into a giant "export PYTHONPATH=..." statement and put that in a .bashrc. There must be a better way?

Python 2.7.3, Django 1.4.1.

Community
  • 1
  • 1
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219

2 Answers2

1

Ok, a simpler way:

export PYTHONPATH='/opt/app/current':`ls -d -1 /opt/app/current/eggs/* | tr '\n' ':'`
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
1

The alternative that we were looking at was to add something like this to the buildout.cfg

 [python_wrapper]
 recipe = zc.recipe.egg
 eggs = ${buildout:eggs}
 interpreter = python

and add python_wrapper to the parts list.

But the workaround that you tweeted (to version lock to an older version of celery) is better. This is a celery bug, and it is better to wait for the developers to fix it.

(So we haven't tried the solution above to see if it actually works ...)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216