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

python 3.12 thread error while using MongoClient() function

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.6.2
    • Affects Version/s: None
    • Component/s: Logging
    • None

      Detailed steps to reproduce the problem?

      Definition of done: what must be done to consider the task complete?

      Whenever i use the MongoClient() function to log in, it displays a python thread error. What is strange is that when using debugging, everything run perfectly, same for when I use a time.sleep(1) function to delay the end of the programs.

       

      Here is the code used, knowing that the identification string is correct :

      rom pymongo import MongoClient
      from my_libs.cryptoFunction import decrypt
      
      
      
      oath_path = "C:/Users/etien/OneDrive - Groupe ESSCA/backup/Scraping Mathieu 2/DbOath"
      oath = decrypt(oath_path)
      client = MongoClient(oath)
      print('ok')

       
      And here is the console log:
       

       
      
      (.venv) PS C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2> & "c:/Users/etien/OneDrive - Groupe ESSCA/backup/Scraping Mathieu 2/.venv/Scripts/python.exe" "c:/Users/etien/OneDrive - Groupe ESSCA/backup/Scraping Mathieu 2/test.py"
      Key file
      'C:/Users/etien/OneDrive - Groupe ESSCA/backup/Scraping Mathieu 2/DbOath/key.txt' accepted.
      Secret file
      'C:/Users/etien/OneDrive - Groupe ESSCA/backup/Scraping Mathieu 2/DbOath/secret.txt' accepted.
      ok
      Exception in thread pymongo_server_monitor_thread:
      Traceback (most recent call last):
      Exception in thread pymongo_server_monitor_thread:
      Traceback (most recent call last):
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
      Exception in thread pymongo_server_monitor_thread:
      Traceback (most recent call last):
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
          self.run()
          self.run()
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1010, in run
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1010, in run
          self.run()
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1010, in run
          self._target(*self._args, **self._kwargs)
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 133, in _run
          self._target(*self._args, **self._kwargs)
          self._target(*self._args, **self._kwargs)
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 133, in _run
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 133, in _run
          if not self._target():
                 ^^^^^^^^^^^^^^
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 61, in target    
          if not self._target():
          if not self._target():
                 ^^^^^^^^^^^^^^
                 ^^^^^^^^^^^^^^
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 61, in target    
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 61, in target    
          monitor._run()  # type:ignore[attr-defined]
          monitor._run()  # type:ignore[attr-defined]
          ^^^^^^^^^^^^^^
          ^^^^^^^^^^^^^^
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 213, in _run     
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 213, in _run     
          monitor._run()  # type:ignore[attr-defined]
          self._start_rtt_monitor()
          ^^^^^^^^^^^^^^
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 167, in _start_rtt_monitor
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 213, in _run     
          self._start_rtt_monitor()
          self._rtt_monitor.open()
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 167, in _start_rtt_monitor
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 87, in open      
          self._start_rtt_monitor()
          self._rtt_monitor.open()
          self._executor.open()
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 87, in open      
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 95, in open
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 167, in _start_rtt_monitor
          self._executor.open()
          thread.start()
          self._rtt_monitor.open()
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 992, in start
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\monitor.py", line 87, in open      
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 95, in open
          _start_new_thread(self._bootstrap, ())
      RuntimeError: can't create new thread at interpreter shutdown
          self._executor.open()
          thread.start()
        File "C:\Users\etien\OneDrive - Groupe ESSCA\backup\Scraping Mathieu 2\.venv\Lib\site-packages\pymongo\periodic_executor.py", line 95, in open
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 992, in start
          thread.start()
        File "C:\Users\etien\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 992, in start
          _start_new_thread(self._bootstrap, ())
      RuntimeError: can't create new thread at interpreter shutdown
          _start_new_thread(self._bootstrap, ())
      RuntimeError: can't create new thread at interpreter shutdown 

      The exact Python version used, with patch level:

      $ python -c "import sys; print(sys.version)"

      3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]

      The exact version of PyMongo used, with patch level:

      $ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"

      4.6.1
      True

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      On a virtual environment,using the command "python -m venv .venv"

      My files are on Onedrive.

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      Windows 11 Home Insider Preview

      Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)

      Security Vulnerabilities

            Assignee:
            jib.adegunloye@mongodb.com Jib Adegunloye
            Reporter:
            etienne.larchetpro@gmail.com Étienne LARCHET
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: