Hello Graham,
I'm working on some application code that will setup an "environment" at the start of a request, and tear it down at the end. The environment would include authorization information, a database connection (if needed), a file server connection (if needed), and the user's session.
Since the daemon process contains several threads, steps need to be take to make sure that certain resources are only used by one thread at a time. A database connection, for example.
Knowing when a request starts is easy -- the `application` callable is called.
Knowing when a request is finished (or terminated), is where I am stuck.
The `application(environ, start_response)` callable is called, and eventually returns an iterator. Plain iterators are not the issue.
It's possible for the `application` callable to return a generator, which could yield a good deal of content. Perhaps it's streaming a file from a fileserver connection, or a large number of records from a database connection. AFAIK, the generator will continue to be called in the same thread until it's finished, and that thread will not be reused until after that point.
But... What's a clean (bullet proof) way to know when mod_wsgi has "finished" a request on a thread?
Thanks!
Jason Garber