Note: In CPython the monitor is no longer a daemon thread. This means that
care must be taken in the interactive shell and simple scripts to set
ReplicaSetConnection references to None so the monitor dies.
The monitor is still a daemon thread in Jython and PyPy.
Big change to PyMongo connection pooling:
* While we still allocate a socket per thread by default, this is now optional. It is also possible to share sockets among threads, safely, and thus using fewer total sockets, by creating a Connection or ReplicaSetConnection with auto_start_request=False.
* In the past, when a thread died without calling end_request() its socket was closed. We now reclaim such sockets for the pool, which should reduce connection churn.
* start_request() now returns a context manager so you can do "with connection.start_request():"
* ReplicaSetConnection now supports start_request, although its semantics aren't consistent for ReadPreferences other than PRIMARY
* Refactoring: Connection and ReplicaSetConnection had different pool implementations, now they share one.
Also PYTHON-162 and PYTHON-189.
Credit goes to James Murty for most of the patch.
With this change we cache auth credentials (user,
password) in the driver so that each new socket
can be automatically authenticated. This solves
the problem of each new spawned thread having to
re-authenticate.
Makes driver ~2x faster for simple benchmarks.
DEPRECATED pool_size, auto_start_request and timeout parameters to Connection
DEPRECATED Connection.start_request
Each thread now gets it's own socket reserved on it's first operation. Those
sockets are held until Connection.end_request is called by that thread, or
Connection.disconnect is called by any thread, or the thread dies.
Calling Connection.end_request allows the socket to be returned to the pool,
and to be used by other threads instead of creating a new socket. Judicious use
of this method is important for applications with many threads or with long
running threads that make few calls to PyMongo operations.
Exception in thread Thread-58 (most likely raised during interpreter shutdown): Exception in thread Thread-62 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
File "/home/art/git/mongo-python-driver/test/test_threads.py", line 31, in run
File "/home/art/git/mongo-python-driver/pymongo/cursor.py", line 411, in next
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
Signed-off-by: Mike Dirolf <mike@dirolf.com>