On 23 June 2010 11:18, DrMeers <[email protected]> wrote: > Hi Graham, > > Just an update as requested -- I modified my standard WSGI script > based on your recommendations (mostly, see below), which seems to have > solved the inter-project-entanglement issues nicely. Unsurprisingly, > the RAM usage is higher from the outset, but that is a small price to > pay for stability! Given the discussions on django-developers at the > moment, I thought this might be timely information for you.
Yes, if I can only find some time to progress some ideas I have to clean up WSGI deployment mess and get that model adopted for Django. :-) > Cheers, > Simon > > PS. I hope to meet you at PyCon this weekend. I presume you will be at my talk? > #--------------------------------------------------- > > import sys > sys.stdout = sys.stderr # avoid WSGI errors caused by writing to > stdout You don't need to remap stdout if using mod_wsgi 3.0+. See: http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html > sys.path = [ > '<home>/webapps/django/%s' % PROJECT_NAME, # within project > '<home>/.pythonpath', # other packages > ] + sys.path > > settings = __import__(locals().get('SETTINGS_MODULE_NAME', > 'settings')) > > import version_loader > version_loader.load(settings.VERSIONS) Can you explain what the above with the __import__ and version_loader is intending to achieve? Is that something of your own? Graham > import django.core.management > django.core.management.setup_environ(settings) > utility = django.core.management.ManagementUtility() > command = utility.fetch_command('runserver') > command.validate() > > import django.conf > import django.utils > django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE) > > import django.core.handlers.wsgi > application = django.core.handlers.wsgi.WSGIHandler() > > #--------------------------------------------------- > > On May 18, 6:57 pm, Graham Dumpleton <[email protected]> > wrote: >> For starters read: >> >> http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html >> >> The standard WSGI script contents as described by Django's own >> documentation, in my opinion has various problems with it. This is >> because it lazily loads things which can cause issues with >> multithreaded hosting. The solution is to force loading and especially >> the auto discover aspects of Django to happen up front in single >> blocking thread, ie., when WSGI script file is being first loaded. >> This was the potential to eliminate various issues. >> >> So, take your WSGI script customisations for paths etc and apply them >> to the WSGI script file contents described at the end of that blog >> post and see if it makes a difference. >> >> Please let us know if that solves your problems as still waiting to >> good confirmation that it does before I update documentation for >> Django on mod_wsgi touse such a recipe. >> >> Graham >> >> On 18 May 2010 17:22, SimonMeers<[email protected]> wrote: >> >> >> >> > This is almost definitely my own silly mistake somewhere, but it has >> > been driving me crazy for weeks now so thought I'd better check if >> > anyone else has come across it. Very intermittently (every couple of >> > days), I'll receive a Django error email containing something like >> > [1]. It is usually an ImportError, where <PROJECT_B>.wsgi has loaded >> > urls.py from <PROJECT_A> and tried to import an app from the other >> > project. Once or twice it has been an ImproperlyConfigured where >> > <PROJECT_B> has tried load middleware from <PROJECT_C>, etc. It occurs >> > with two particular projects most frequently, but they often swap, and >> > sometimes other projects get involved. >> >> > My httpd.conf can be found below [2]. I'm using mod_wsgi SVN. My >> > standard WSGI script is also provided [3]. >> >> > Any ideas? >> >> > Thanks, >> > Simon >> >> > [1] Traceback (most recent call last): >> >> > File "<HOME>/lib/django_1.2/django/core/handlers/base.py", line 91, >> > in get_response >> > request.path_info) >> >> > File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 214, in >> > resolve >> > for pattern in self.url_patterns: >> >> > File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 243, >> > in _get_url_patterns >> > patterns = getattr(self.urlconf_module, "urlpatterns", >> > self.urlconf_module) >> >> > File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 238, >> > in _get_urlconf_module >> > self._urlconf_module = import_module(self.urlconf_name) >> >> > File "<HOME>/lib/django_1.2/django/utils/importlib.py", line 35, in >> > import_module >> > __import__(name) >> >> > File "<HOME>/webapps/django/<PROJECT_A>/urls.py", line 5, in <module> >> > admin.autodiscover() >> >> > File "<HOME>/lib/django_1.2/django/contrib/admin/__init__.py", line >> > 20, in autodiscover >> > mod = import_module(app) >> >> > File "<HOME>/lib/django_1.2/django/utils/importlib.py", line 35, in >> > import_module >> > __import__(name) >> >> > ImportError: No module named <APP_FROM_PROJECT_A> >> >> > <WSGIRequest >> > GET:<QueryDict: {}>, >> > POST:<QueryDict: {}>, >> > COOKIES:{}, >> > META:{'DOCUMENT_ROOT': '/etc/httpd/htdocs', >> > 'GATEWAY_INTERFACE': 'CGI/1.1', >> > 'HTTP_ACCEPT_ENCODING': 'identity', >> > 'HTTP_CONNECTION': 'Keep-Alive', >> > 'HTTP_HOST': '<PROJECT_B_DOMAIN>', >> > 'HTTP_USER_AGENT': 'Python-urllib/2.6', >> > 'HTTP_X_FORWARDED_FOR': '<CLIENT_IP>', >> > 'HTTP_X_FORWARDED_HOST': '<PROJECT_B_DOMAIN>', >> > 'HTTP_X_FORWARDED_SERVER': '<PROJECT_B_DOMAIN>', >> > 'PATH_INFO': u'/', >> > 'PATH_TRANSLATED': '<HOME>/webapps/django/<PROJECT_B>.wsgi/', >> > 'QUERY_STRING': '', >> > 'REMOTE_ADDR': '127.0.0.1', >> > 'REMOTE_PORT': '59766', >> > 'REQUEST_METHOD': 'GET', >> > 'REQUEST_URI': '/', >> > 'SCRIPT_FILENAME': '<HOME>/webapps/django/<PROJECT_B>.wsgi', >> > 'SCRIPT_NAME': u'', >> > 'SERVER_ADDR': '127.0.0.1', >> > 'SERVER_ADMIN': '<SERVER_ADMIN_EMAIL>', >> > 'SERVER_NAME': '<PROJECT_B_DOMAIN>', >> > 'SERVER_PORT': '80', >> > 'SERVER_PROTOCOL': 'HTTP/1.1', >> > 'SERVER_SIGNATURE': '', >> > 'SERVER_SOFTWARE': 'Apache', >> > 'mod_wsgi.application_group': '<PROJECT_B_DOMAIN>|', >> > 'mod_wsgi.callable_object': 'application', >> > 'mod_wsgi.handler_script': '', >> > 'mod_wsgi.input_chunked': '0', >> > 'mod_wsgi.listener_host': '', >> > 'mod_wsgi.listener_port': '<PORT_NUMBER>', >> > 'mod_wsgi.process_group': 'AEST', >> > 'mod_wsgi.request_handler': 'wsgi-script', >> > 'mod_wsgi.script_reloading': '1', >> > 'mod_wsgi.version': (4, 0), >> > 'wsgi.errors': <mod_wsgi.Log object at 0xa971cf0>, >> > 'wsgi.file_wrapper': <built-in method file_wrapper of >> > mod_wsgi.Adapter object at 0xa978458>, >> > 'wsgi.input': <mod_wsgi.Input object at 0xa971ed0>, >> > 'wsgi.multiprocess': False, >> > 'wsgi.multithread': True, >> > 'wsgi.run_once': False, >> > 'wsgi.url_scheme': 'http', >> > 'wsgi.version': (1, 1)}> >> >> > [2] httpd.conf: >> > ServerRoot "<HOME>/webapps/django/apache2" >> >> > LoadModule dir_module modules/mod_dir.so >> > LoadModule env_module modules/mod_env.so >> > LoadModule log_config_module modules/mod_log_config.so >> > LoadModule mime_module modules/mod_mime.so >> > LoadModule rewrite_module modules/mod_rewrite.so >> > LoadModule wsgi_module modules/mod_wsgi.so >> > LoadModule alias_module modules/mod_alias.so >> > LoadModule authz_host_module modules/mod_authz_host.so >> > LoadModule auth_digest_module modules/mod_auth_digest.so >> > LoadModule authz_user_module modules/mod_authz_user.so >> > LoadModule authn_file_module modules/mod_authn_file.so >> > LoadModule proxy_module modules/mod_proxy.so >> >> > KeepAlive Off >> > Listen <PORT_NUMBER> >> >> > ServerSignature Off >> > ServerTokens Prod >> >> > StartServers 1 >> > MinSpareServers 1 >> > MaxSpareServers 3 >> > MaxClients 5 >> > MaxRequestsPerChild 100 >> > ServerLimit 4 >> > HostnameLookups Off >> >> > NameVirtualHost 127.0.0.1:<PORT_NUMBER> >> > ServerAdmin <SERVER_ADMIN_EMAIL> >> >> > # Run in separate group to avoid timezone issues >> > #http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_... >> > WSGIDaemonProcess UTC maximum-requests=100 inactivity-timeout=60 >> > display-name=%{GROUP} >> > WSGIDaemonProcess AEST maximum-requests=100 inactivity-timeout=60 >> > display-name=%{GROUP} >> > # (frequent restarts to keep memory down on shared hosting package) >> >> > WSGIRestrictEmbedded On >> > # (http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html) >> >> > <VirtualHost 127.0.0.1:<PORT_NUMBER>> >> > WSGIProcessGroup AEST >> > WSGIScriptAlias / <HOME>/webapps/django/<PROJECT_A>.wsgi >> > ServerName <PROJECT_A_DOMAIN> >> > </VirtualHost> >> >> > <VirtualHost 127.0.0.1:<PORT_NUMBER>> >> > WSGIProcessGroup AEST >> > WSGIScriptAlias / <HOME>/webapps/django/<PROJECT_B>.wsgi >> > ServerName <PROJECT_B_DOMAIN> >> > </VirtualHost> >> >> > # etc. Twenty or so more sites here... >> >> > [3] Standard WSGI script: >> > import os >> > import sys >> >> > # avoid WSGI errors with output to stdout >> > sys.stdout = sys.stderr >> >> > sys.path = [ >> > '<HOME>/webapps/django', # for PROJECT_NAME >> > '<HOME>/.pythonpath', # other packages >> > '<HOME>/webapps/django/%s' % PROJECT_NAME, # within project >> > ] + sys.path >> >> > settings_module_path = '%s.%s' % (PROJECT_NAME, SETTINGS_MODULE_NAME) >> >> > os.environ['DJANGO_SETTINGS_MODULE'] = settings_module_path >> >> > from django.core.handlers.wsgi import WSGIHandler >> > application = WSGIHandler() >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "modwsgi" group. >> > To post to this group, send email to [email protected]. >> > To unsubscribe from this group, send email to >> > [email protected]. >> > For more options, visit this group >> > athttp://groups.google.com/group/modwsgi?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "modwsgi" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group >> athttp://groups.google.com/group/modwsgi?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
