title: How to set connection timeout for Mongodb using pymongo?
body: <p>I tried setting <code>connectTimeoutMS</code> and <code>socketTimeoutMS</code> to a low value but it still takes about 20 seconds before my script times out. Am I not using the options correctly? I want the script to exit after 5 seconds.</p>
  
  <pre><code>def init_mongo():
      mongo_connection = MongoClient('%s' %MONGO_SERVER, connectTimeoutMS=5000, socketTimeoutMS=5000)
      if mongo_connection is None:
          return
  
      try:
          &lt;code&gt;
      except:
          &lt;code&gt;
  </code></pre>