Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3290

[csot] Define behavior of nesting pymongo.timeout

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Define behavior of nested pymongo.timeout call. Options:

      1. 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
        
      2. 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({}) 
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: