/ _ah / queue / delayed strange import error

I have django 1.5 running on the Google App Engine using the djangoappengine module for stitching. Everything works fine, except that about half of the calls to / _ah / queue / offfer 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 is inside the third_party directory, and this directory is added to sys.path in the appengine_config.py file, so there should not be any problems doing from djangoappengine import main :

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

Corresponding line in app.yaml :

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

What causes these sporadic import errors? Am I doing something wrong? Maybe there is an import cycle that I don't know about?

+6
source share
2 answers

I found out that my code used the old CGI interface instead of the new WSGI. I fixed this and the problem has not returned since.

Updated app.yaml :

 handlers: - url: /_ah/queue/deferred script: djangoappengine.deferred.handler.application login: admin 
+2
source

The deffer library is known to do some funky things with third-party importers. This is because if a deferred task loads a new instance, third-party libraries load slowly. You have 2 options (with the third I'm not sure what will work)

  • Use standard call on call. I can help you rewrite it if necessary.
  • If you just need django and not the special djangoappengine library, you should use the one application engine. They guarantee downloads.
  • I don't know if this will work, but it may be worth a try, put the import in a try loop until it is loaded. His simple idea never tried to do it myself.
+1
source

Source: https://habr.com/ru/post/972228/


All Articles