2

I have put my Django web site up to my web server and have it set up using apache2 and mod_wsgi.. everything works fine most of the time but occasionally it will just give the error that it can't import a module (usually from my views file). However, it's not an issue with that module as it usually works, for example, I will get the error "Cannot import classname from module" once, then reload the page and it works fine, I would say it's about 1 in 10 page loads where this occurs and it's just random as it will happen for any page on my site.

I have tried restarting apache2, restarting the server but the issue persists. I have tried it on different client machines, clearing out the user cache, etc but the issue persists. I don't know what might be doing this, would perhaps some sort of caching help prevent this as it seems that the server is just having an issue with sometimes not being able to fully process the request. I am using a cloud set up with not much memory on the server so maybe this is the problem? Any advice is appreciated

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
Rick
  • 16,612
  • 34
  • 110
  • 163
  • 1
    Is the import that fails always the same? Does this ever happen on the dev server? And similarly, if you run apache w/ a single thread, does it still happen? Do you have any other sites running mod_wsgi under the same apache instance? – Sam Dolan Sep 20 '10 at 06:23
  • I'm not 100% sure if its always the same module, will have to take note of it from this point forward, so I will update the posting a bit later.. I will also try apache in single thread as I think I have it running multi thread but am not sure, its just the one django site so no other sites – Rick Sep 20 '10 at 06:29
  • 1
    My guess is it's a race condition in the multithreading. Try to see if you can at least get it working consistently in single threaded mode, then switch over to multithreaded mode and save as much stacktrace as you can. Sorry to say, but this may get ugly. – Sam Dolan Sep 20 '10 at 06:35
  • When you say a cloud setup, do you mean there are multiple machines that can service any query? Or just that your hosted services is 'in' someone else's cloud, but a single computer? Also -- is it always the same module or does it change? – synthesizerpatel Sep 20 '10 at 06:49
  • Thanks for the tips, I'm just going to put it into single thread for now as that should be fine, its a low traffic site anyways.. will look into this more for future uses of multi-threading – Rick Sep 20 '10 at 09:41
  • Actually, I don't think I am running a multi-thread (after checking).. this just makes this all the more puzzling – Rick Sep 20 '10 at 10:33

1 Answers1

1

It is working most of the time because you likely have a multi process configuration and only one of the processes is affected.

You can try alternate WSGI script file as documented in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

The jury is still out as to whether the issue is the differences between development server and proper deployment systems using WSGI, or whether it is users not handling imports properly and causing order dependencies or even import cycles. Problems possibly only come up when URL visited in certain order and thus why random as to when it can happen.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134