Define behavior of nested pymongo.timeout call. Options:
- nested timeout() call acts independently:
with pymongo.timeout(1): client.test.test.insert_one({}) with pymongo.timeout(5): client.test.test.insert_one({}) # Will timeout using the 5 second deadline
- nested timeout() call can only shorten the deadline, not extend it.
with pymongo.timeout(1): client.test.test.insert_one({}) with pymongo.timeout(5): client.test.test.insert_one({}) # Will timeout using the original 1 second deadline
Option 1) violates the contract of timeout() in the sense that the block of code will not raise a timeout when the original timeout has expired so option 2) makes more sense in my opinion.
We can always add support for option 1) at a later date via a new parameter, for example:
with pymongo.timeout(1): client.test.test.insert_one({}) # Shield from outer timeouts/deadlines and use 5 sec deadline: with pymongo.timeout(5, shield=True): client.test.test.insert_one({})
- depends on
-
PYTHON-3288 [csot] Add pymongo.timeout() context manager API
- Closed