Python Forum
Error: can't start new thread - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error: can't start new thread (/thread-40171.html)



Error: can't start new thread - maha2 - Jun-13-2023

Hi!
When creating an instance of the pymongo.MongoClient class, I have the following error at irregular intervals:

Error:
... File "/srv/foo/src/bar.mongodb.core/bar/mongodb/core/clients.py", line 78, in get_client db_clients_uri[key] = pymongo.MongoClient(host) File "/home/foo/src/pymongo-3.12.1-py3.6-linux-x86_64.egg/pymongo/mongo_client.py", line 779, in __init__ self._get_topology() File "/home/foo/src/pymongo-3.12.1-py3.6-linux-x86_64.egg/pymongo/mongo_client.py", line 1297, in _get_topology self._kill_cursors_executor.open() File "/home/foo/src/pymongo-3.12.1-py3.6-linux-x86_64.egg/pymongo/periodic_executor.py", line 87, in open thread.start() File "/home/foo/src/Python-3.6/lib/python3.6/threading.py", line 846, in start _start_new_thread(self._bootstrap, ()) RuntimeError: can't start new thread
To investigate, I have included a log in threading.py at the appropriate point in the exception handling of the handler 'start':

from logging import getLogger
logger = getLogger('threading')
try:
    import subprocess
    total, used, free = map(
        int, subprocess.check_output(['free', '-t']).splitlines()[-1].split()[1:])
    logger.error('### RAM memory used: {} %'.format(str(round((used/total) * 100, 2))))
    import threading
    logger.error('### PYTHON threads: '+str(threading.active_count()))
except Exception as err:
    logger.error('### RAM memory error '+str(err))
In the logs I have the following result:
RAM memory error [Errno 11] Resource temporarily unavailable

Can the log output be interpreted unambiguously?
a) When calling subprecess.check_output(), it is simply no longer possible to create new threads due to the thread problem or
b) the RAM limit has been reached or
c) ?

Thank you very much!