Hi Alex,

mp> I've found it to be way more practical to just store the request object
mp> inside a threading.local object and let my functions access it directly.
mp> (...)

Alex> Quite simply, no.  Storing anything in a threadlocal instead of
Alex> passing it around is indicative of bad coding practice, and poor
Alex> architecture.

Stating that the use of threading.local objects is "indicative of bad
coding practice, and poor architecture" is plainly wrong.

I say: It depends.

Django is probably most famous for it's easy to use ORM and steep
learning curve. This surely wasn't the case if you had to pass around
some database session object all the time. I'd go that far to say if the
ORM wasn't so nice to use I would never have picked up Django in the
first place.

Some people claim that thread locals kill performance, but that's mainly
caused by bad code design. Looking up some thread local object a
bazillion times in a loop can be avoided just like most 1+N database
queries.

If Django was designed with c10k in mind with a sophisticated non
blocking IO event dispatcher I couldn't agree more with you. In this
case using threading.local object would in fact be an architectural
disaster. Since Django is essentially build around the 'one request =
one thread' idiom it's perfectly valid to use a threading.local object
for storing the request object inside.

Django was designed with a 'get things done' mentality. It is a
framework for perfectionists with deadlines. So instead of making it
difficult to query the database it provides a convenient way of
providing access to the database connection in a threading.local object.

So I wonder what would be wrong with putting the request object in a
threading.local object. It would neither kill performance nor cause a
poor architecture by itself.


I've spent way too much time with frameworks that aim for a perfect
architecture, but fail horribly when it comes to productivity. I finally
came to Django to get my work done and not having to monkey patch the
framework continuously.


--mp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to