Hi, I'm finally reviewing and testing this. I applied your patch to HEAD
and I'm testing it with Python 2.7.3,
currently test_max_pool_size_with_leaked_request
and test_max_pool_size_with_redundant_request fail reliably. I'll try to
figure out why.

Do be careful with the admonition in _set_request_state, "Do not access
threadlocals in this function, or any function it calls!" Your addition
of ident.unwatch() to on_thread_died() would access a threadlocal and bring
back PYTHON-353 in Python 2.6 and mod_wsgi 2.8. We'd catch that in our
testing, since we test that combo, but just be aware of that. More info
here:

http://emptysquare.net/blog/knowing-when-a-python-thread-has-died/




On Tue, Apr 2, 2013 at 3:26 PM, Justin Patrin <notifications@github.com>wrote:

> In pymongo/pool.py:
>
> > @@ -363,16 +402,18 @@ def maybe_return_socket(self, sock_info):
> >      def _return_socket(self, sock_info):
> >          """Return socket to the pool. If pool is full the socket is discarded.
> >          """
> > -        try:
> > -            self.lock.acquire()
>
> Yep, I think I removed that during an earlier revision where I was
> handling this in another way. I've readded it.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/mongodb/mongo-python-driver/pull/163/files#r3624789>
> .
>