Tzach
Tzach

Reputation: 13376

/_ah/queue/deferred strange import error

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?

Upvotes: 6

Views: 394

Answers (2)

Tzach
Tzach

Reputation: 13376

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

Upvotes: 2

Ryan
Ryan

Reputation: 2542

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

Upvotes: 1

Related Questions