Re: Local thread variable (attempting to create a connection pool)

2012-12-14 Thread Rafael Almeida
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:
>
> 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 singletons
>
> Here's some starters:
>
> http://stackoverflow.com/questions/42558/python-and-the-singleton-pattern
>
>
>
>
> 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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Local thread variable (attempting to create a connection pool)

2012-12-14 Thread Rafael Almeida
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/-/lBxQ609aeDcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.