tag:blogger.com,1999:blog-2363643920942057324.post6436998120984913197..comments2023-08-09T23:00:54.857+10:00Comments on Graham Dumpleton: Requests running in wrong Django instance under Apache/mod_wsgi.Graham Dumpletonhttp://www.blogger.com/profile/13609779138164842374noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-2363643920942057324.post-89698571257074686812015-10-20T15:07:28.893+11:002015-10-20T15:07:28.893+11:00YOU ARE AWESOME! os.envrion.setdefault was ruining...YOU ARE AWESOME! os.envrion.setdefault was ruining me! Thanks!Anonymoushttps://www.blogger.com/profile/07479545975284072022noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-10677995073389440092014-05-22T09:44:40.389+10:002014-05-22T09:44:40.389+10:00@hdante The use of assignment is not a race condit...@hdante The use of assignment is not a race condition for the documented example given in the blog post because it is done at global scope within the WSGI script file. The WSGI script file would be loaded once and the loading is under the context of an import lock and so only one request thread can trigger the loading. There is thus no possibility for the assignment in that specific WSGI script Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-63931884952402256102014-05-22T03:19:07.025+10:002014-05-22T03:19:07.025+10:00@Graham The point is that the text suggests, as so...@Graham The point is that the text suggests, as solution for multiple django settings "to replace the use of setdefault() to set the environment variable in the WSGI script file with more usual assignment". This is not supposed to work if apache is using worker or event MPM, because starting 2 threads would cause a race when setting the environment variable on each thread.hdantehttps://www.blogger.com/profile/17371423835431603557noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-12581803423327136382014-05-21T09:01:30.356+10:002014-05-21T09:01:30.356+10:00@hdante If you are specific help in working out an...@hdante If you are specific help in working out an issue, please use the mod_wsgi mailing list as mentioned at:<br /><br />http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Asking_Your_Questions<br /><br />In short though, setting os.environ to different values on a per request basis is dangerous in any multithreaded application and not just mod_wsgi and will cause lots of issues. You Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-28979207701246823322014-05-21T07:56:24.729+10:002014-05-21T07:56:24.729+10:00I could not confirm that using assignment on envir...I could not confirm that using assignment on environ solves the problem when using multiple threads with apache. Two threads may call os.environ[...] = settings1, then settings2 in sequence and the end result will be that both will run with settings2. Can you confirm this ?<br /><br />I'm currently experiencing lots of invalid ALLOWED_HOSTS errors in my dual virtual host setup and the only hdantehttps://www.blogger.com/profile/17371423835431603557noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-20865916450951416732013-11-11T05:15:57.139+11:002013-11-11T05:15:57.139+11:00Thank you for posting this Graham.
I seem to have...Thank you for posting this Graham.<br /><br />I seem to have been running into your answers on a lot of Django deployment questions I've been searching lately. I appreciate the sharing!Wilderhttps://www.blogger.com/profile/16809737343974550571noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-56434347258961843642013-09-30T12:24:24.334+10:002013-09-30T12:24:24.334+10:00Thanks Graham, Your article clearly explained my p...Thanks Graham, Your article clearly explained my problem and enabled me to efficiently fix it and to understand apache a little better as a bonus.Anonymoushttps://www.blogger.com/profile/03479282258120066571noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-1497733752570323132013-04-02T08:04:47.428+11:002013-04-02T08:04:47.428+11:00@Tomas The leakage of environment variables is bet...@Tomas The leakage of environment variables is between Python sub interpreters within the one process, not between separate processes.Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-48859099014807785192013-04-02T06:49:30.105+11:002013-04-02T06:49:30.105+11:00This is really helpful. I had problem with environ...This is really helpful. I had problem with environment variables leakage between processes and I realized, that I hadn't been using attribute "process-group" in WSGIAlias command.Tomas Tomecekhttps://www.blogger.com/profile/04479625127024575386noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-80753616396560766582013-02-07T13:37:32.449+11:002013-02-07T13:37:32.449+11:00WSGIScriptAlias and WSGIDaemonProcess group direct...WSGIScriptAlias and WSGIDaemonProcess group directives can only be added into the main Apache configuration file and not in a .htaccess file. Typically the main Apache configuration will require root access to modify the configuration files. That is the only way root comes into it. The feature implemented by those directives works fine if Apache was started as a user other than root.Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-1815917526440380102013-02-07T06:10:03.807+11:002013-02-07T06:10:03.807+11:00If you specify "WSGIScriptAlias … process-gro...If you specify "WSGIScriptAlias … process-group=" syntax or the WSGIProcessGroup doesn't that <b>only</b> work if you are <a href="http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess" rel="nofollow">running Apache as root</a>?Unknownhttps://www.blogger.com/profile/14934263854085545692noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-68215626435933138192012-11-17T09:48:13.218+11:002012-11-17T09:48:13.218+11:00More a case of when I was working on this I was mo...More a case of when I was working on this I was moving so quick was hard for anyone to catch up with what was going on so as to be able to contribute. Now it is very stable and so the need to do anything else has dropped dramatically. Delving into the C APIs of both Apache and Python also isn't going to be of interest to most people, so was always going to be a very small pool of people one Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-35676243065207552202012-11-17T00:22:37.167+11:002012-11-17T00:22:37.167+11:00how come nobody else in the python community wants...how come nobody else in the python community wants to help? I think it is not your fault if you can't dedicate time to it, it's open source, those who use it should contribute.<br />Have you ever tried mentoring a student for the Google Summer of Code?Nemesis Designhttps://www.blogger.com/profile/17006834524646702289noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-47922793039605121092012-11-16T20:35:36.273+11:002012-11-16T20:35:36.273+11:00Yep, only one mad enough to do it. Unfortunately d...Yep, only one mad enough to do it. Unfortunately don't get as much time to devote to it now as I once did.Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-69328939646844776812012-11-16T20:32:28.942+11:002012-11-16T20:32:28.942+11:00Great work Graham, thank you for all your effort. ...Great work Graham, thank you for all your effort. It looks like you are the only one working on this project, is it really so?<br />Fed.Nemesis Designhttps://www.blogger.com/profile/17006834524646702289noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-65809831545408320732012-10-11T15:00:25.541+11:002012-10-11T15:00:25.541+11:00Yes, the mod_wsgi documentation has lots of stuff ...Yes, the mod_wsgi documentation has lots of stuff missing. And yes daemon mode is the better option for most. I'll hopefully be saying more about this in future blog post and if not at PyCon if talk gets accepted.<br /><br />Wish I had more time. :-)<br />Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-67751503057645131802012-10-10T01:54:12.157+11:002012-10-10T01:54:12.157+11:00In 2012, with modern Python/Apache/mod_wsgi/etc. w...In 2012, with modern Python/Apache/mod_wsgi/etc. why would someone choose not to use WSGIDaemonProcess by default? I strongly prefer it for reliability and security (when using a separate user, of course) and have thought that some of the deployment questions I've seen in the Django world could be avoided if the default recommendation was to use a daemon rather than in-process instance.<br />Chris Adamshttps://www.blogger.com/profile/06132981126518774942noreply@blogger.com