On Thu, Oct 17, 2013 at 4:24 AM, Jonathan Slenders < [email protected]> wrote:
> The global state problem is something that's been bothering me for a long > while, but after seeing a presentation of Alex Gaynor [1] from last year, I > started thinking about this again. > > The main problem is that you'd need to have a DjangoProject object which > contains the root configuration and you'd have to somehow pass that object > around everywhere. > > Maybe I'm not the first to think about this, but what's wrong with > thread-local-storage? > What's wrong with thread local storage? Well, try this though experiment. Everywhere that you see the word "thread local", replace it with "global variable". Now re-read your argument. It doesn't matter how you gussy it up -- a thread local is a global variable, with all the software engineering consequences that follow from that, including increased coupling, decreased cohesion, complications for testing, and so on. > In Django, we have a huge advantage above nodejs in that there's only one > active request per thread and that request should belong to only one > DjangoProject instance. (We don't have unexpected contextswitches in the > same thread, like in Twisted or Tulip. -- We can make that assumption.) > Yet. :-) I don't know that we can rely on this being true for all time. (This is an admittedly weak argument -- I certainly wouldn't base any objection to thread locals on this alone) Actually we are already using threadlocals for the current active language > [2], so I don't see any reason for not using the same approach to keep > track of the currently active DjangoApplication object. > You're correct -- however, I'd call this a wart, not a pattern to be followed. If we were in a position to remove these thread locals, I would. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAJxq848XP6mqctJ3dkMVKbzMkpk%3DChETGy3Ws_oORt9xnArzfA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
