Re: Local thread variable (attempting to create a connection pool)
I'm not sure it's really a singleton that I need because I need a different value for each thread. I'm using threading.local for it, so far I haven't run into any issues, but I'd like to hear the opinion of a more experienced django developer.
I save in cache the possible IPs of the backend system and I open connections to it when needed inside a threading.local subclass. I use an object from such class in order to retrieve a connection.
The threading.local subclass is instantiated in a module variable, I could use the singleton class you pointed out as well. But I don't see the need for it in my case.
On Friday, December 14, 2012 5:38:59 PM UTC-2, Chris Cogdon wrote:
-- On Friday, December 14, 2012 5:38:59 PM UTC-2, Chris Cogdon wrote:
What you essentially want is a common pattern called a "singleton": something that there is only one of, like "None" and "Elipsis". You can do something workable, but ugly, using module-level variables, but there are known patterns for creating singletonsHere's some starters:
On Friday, December 14, 2012 9:33:19 AM UTC-8, Rafael Almeida wrote:Hello,I have a django application which needs to connect to some backend services. Problem is I don't want to create a new connection everytime, but to use a connection pool. One connection per thread would be fine, but I don't know how to use django in order to achive that. I'd like to perhaps save those connections on cache subsystem, but I don't know how to create one key per thread, per worker.Thank you for your help,Rafael
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/hsdCWcl-2owJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home