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.
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
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:
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
4 matches
Mail list logo