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

2012-12-14 Thread Russell Keith-Magee
Can a thread local work? Yes. Are they a good idea? IMHO - Generally speaking, no. >From a purely architectural point of view, it doesn't matter what you call them -- you're talking about a global variable. Any argument that holds for why global variables are bad also holds for thread locals.

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

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

2012-12-14 Thread Chris Cogdon
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:

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