/_ah/queue/deferred strange import error
Asked Answered
M

2

6

I have a django 1.5 running on Google App Engine using the djangoappengine module for the stitching. Everything works fine, except that about a half of the calls to /_ah/queue/deferred raise the following import error:

Traceback (most recent call last):
  File "..../third_party/djangoappengine/deferred/handler.py", line 2, in <module>
    from djangoappengine import main
ImportError: No module named djangoappengine

As you can see, the djangoappengine module sits inside the third_party directory, and this directory is added to sys.path in the appengine_config.py file, so there shouldn't be any problems doing from djangoappengine import main:

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'third_party'))

The relevant line in app.yaml is:

handlers:
- url: /_ah/queue/deferred
  script: third_party/djangoappengine/deferred/handler.py
  login: admin

What is causing these sporadic import errors? Am I doing something wrong? Maybe there's an import loop I'm not aware of?

Mcilwain answered 15/7, 2014 at 6:51 Comment(1)
Does it work at all if you remove "third_party/" from the script path in app.yaml?Ammoniac
M
2

Found out that my code used old CGI interface instead of the newer WSGI. I Fixed this and the problem didn't return since.

Updated app.yaml:

handlers:
- url: /_ah/queue/deferred
  script: djangoappengine.deferred.handler.application
  login: admin
Mcilwain answered 15/9, 2014 at 10:48 Comment(1)
hello, I am using the same handler as you do and still see that a certain number of tasks don't manage to load all Django environment (in my example it does not see the CACHES env). Anything else you did here?Tompkins
B
1

The deffer library has been known to do some funky things with 3rd party imports. It has something to do with if the deferred task loads a new instance 3rd party libs are slow to get loaded. You have 2 options (with a 3rd I'm not sure will work)

  • Use the standard taskqueue call. I can help you re-write if needed.
  • If you just need django and not the special djangoappengine library you should use the app engine one. They are guarantee to be loaded.
  • No idea if this will work but may be worth a try is put the import in a try except loop until it gets loaded. Its just an idea never tried doing that myself
Bronchia answered 9/9, 2014 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.