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


I have a connection to external processing, which I need to make for my Pilanes app (a database connection Think on the lines.) There is a nominal amount of upper portion involved in setting up connections.

I can set up a portion of the middle request that opens and closes the connection with each request, but it is useless. I want to establish a connection to each new thread that starts up and saves itself overhead. How can I hook into threads in threads?

Is the connection to a thread related to their lifetime?

If not, you may consider applying your own connection pool for this resource. The pool will be responsible for starting the connection and the connection will be required as each thread, acquisition and release .

If you want to limit the number of available connections, you only block during the acquisition phase until the connection is released or some time is over.

To implement such a pool, the code is going to depend much on the resource you are talking about, so it would be difficult to give anything other than the recommended API.


Comments