mongodb/mongo-python-driver — pull request #210 by KonishchevDmitry (2013-10-21 12:01:28+00:00)
Title: Add an option to ignore TimeoutError exception

PyMongo always raises `TimeoutError` when you get wtimeout error from server due to `w=...` and `wtimeout=...` options in write operations. As for me it's almost always not the thing I'd want to get. I need an ability to ignore `TimeoutError` exception to inspect a getLastError object returned by the server like this:

```python
try:
result = collection("foo").update(
{ "_id": "bar", "locked": { "$ne": True } },
{ "$set": { "locked": True } }, w="majority", wtimeout=...)

if result["updatedExisting"]:
log("The document is locked.")

if result.get("wtimeout"):
log("The changes are successfully written to primary, but not to majority.")
else:
log("The changes are successfully written to majority.")
except Exception:
log("Failed to lock the document.")

try:
result = collection("foo").insert(..., w="majority" wtimeout=..., full_response=True)

if result.get("wtimeout"):
log("The changes are successfully written to primary, but not to majority.")
else:
log("The changes are successfully written to majority.")
except Exception:
log("Failed to insert the document.")
```

This pull request adds an ability to ignore `TimeoutError` and obtain a getLastError object like in the above example.