OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Mongo DB connection using pymongo in Python not responding or hangs intermittently

  • Thread starter Thread starter George
  • Start date Start date
G

George

Guest
I am connecting to mongoDB using pymongo MongoClient in python. MongoDB ping command and other operations hangs or gets stuck without responding. This issue occurs intermittently only. In below code block the first print statement works but second print statement never gets printed since the ping command is not responding.

Code:
from pymongo import MongoClient
client = MongoClient(mongo_url)
print("Starting to ping")
ping = client.admin.command('ping')
print("Completed ping")

Note: MongoClient version is 3.10 MongoDB Server version is 4.2 Python version is 3.10

Tried updating code as below but we are not getting any errors or exceptions and no response for infinite time.

Code:
from pymongo import MongoClient
client = MongoClient(mongo_url, waitQueueTimeoutMS=5000, socketTimeoutMS=5000,
                     serverSelectionTimeoutMS=5000, connectTimeoutMS=5000, maxPoolSize=100)
try:
    print("Starting to ping")
    ping = client.admin.command('ping')
    print("Completed ping")
except ConnectionFailure:
    print("Server not available")
except pymongo.errors.PyMongoError as e:
    print("Pymongo error: " + str(e))
except Exception as exc:
    print("Exception: " + str(exc))
<p>I am connecting to mongoDB using pymongo MongoClient in python.
MongoDB ping command and other operations hangs or gets stuck without responding.
This issue occurs intermittently only.
In below code block the first print statement works but second print statement never gets printed since the ping command is not responding.</p>
<pre><code>from pymongo import MongoClient
client = MongoClient(mongo_url)
print("Starting to ping")
ping = client.admin.command('ping')
print("Completed ping")
</code></pre>
<p>Note:
MongoClient version is 3.10
MongoDB Server version is 4.2
Python version is 3.10</p>
<p>Tried updating code as below but we are not getting any errors or exceptions and no response for infinite time.</p>
<pre><code>from pymongo import MongoClient
client = MongoClient(mongo_url, waitQueueTimeoutMS=5000, socketTimeoutMS=5000,
serverSelectionTimeoutMS=5000, connectTimeoutMS=5000, maxPoolSize=100)
try:
print("Starting to ping")
ping = client.admin.command('ping')
print("Completed ping")
except ConnectionFailure:
print("Server not available")
except pymongo.errors.PyMongoError as e:
print("Pymongo error: " + str(e))
except Exception as exc:
print("Exception: " + str(exc))
</code></pre>
 

Latest posts

M
Replies
0
Views
1
Muhammad Rafli Aditya. H
M
Top