Pylons: Proper Way to Establish Per-Thread/Per-Request Resource?

If not, you could consider implementing your own connection pool for this resource. The pool would be responsible for initializing connections and each thread would acquire and release the connections as they are needed If you want to limit the number of available connections, you just block during the acquire phase until a connection is released or some timeout is reached The code to implement such a pool is going to be very dependent on the resource you are talking about, so it would be difficult to give you anything other than a suggested API.

If not, you could consider implementing your own connection pool for this resource. The pool would be responsible for initializing connections and each thread would acquire and release the connections as they are needed. If you want to limit the number of available connections, you just block during the acquire phase until a connection is released or some timeout is reached.

The code to implement such a pool is going to be very dependent on the resource you are talking about, so it would be difficult to give you anything other than a suggested API.

No, they don't have to belong to the same thread, now that I think about it, as long as they are consistent for the duration of a request. As long as I have num_connections >= num_threads, I'd be OK. Any idea how to get the number of threads running?

– dave mankoff Jun 19 '10 at 17:05 Actually - I could just have my acquire method create new connections on demand, up to some limit. I will investigate this, thanks! – dave mankoff Jun 19 '10 at 17:07 I don't think Pylons controls that, but is determined by whatever is hosting your WSGI container, be it Apache/mod_wsgi or other, so not sure if there is a 'portable' way to do it.

However, if you design the connection pool correctly, your application would function properly for any num_connections >= 1 regardless of num_threads. Each thread would just block until a connection became available. (Making a couple of assumptions there, but generally speaking) Then it would just be a matter of finding the sweet spot where you have enough connections in the pool to ensure minimal blocking.

– Joe Holloway Jun 19 '10 at 17:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions