File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,24 @@ def __init__(
125125
126126 client = MongoClient('/tmp/mongodb-27017.sock')
127127
128+ .. note:: Starting with version 3.0 the :class:`MongoClient`
129+ constructor no longer blocks while connecting to the server or
130+ servers, and it no longer raises
131+ :class:`~pymongo.errors.ConnectionFailure` if they are
132+ unavailable, nor :class:`~pymongo.errors.ConfigurationError`
133+ if the user's credentials are wrong. Instead, the constructor
134+ returns immediately and launches the connection process on
135+ background threads. You can check if the server is available
136+ like this::
137+
138+ from pymongo.errors import ConnectionFailure
139+ client = MongoClient()
140+ try:
141+ # The ismaster command is cheap and does not require auth.
142+ client.admin.command('ismaster')
143+ except ConnectionFailure:
144+ print("Server not available")
145+
128146 .. warning:: When using PyMongo in a multiprocessing context, please
129147 read :ref:`multiprocessing` first.
130148
You can’t perform that action at this time.
0 commit comments