python 连接 mongodb 时出现运行错误?

import pymongo
 
myclient = pymongo.MongoClient(host='localhost', port=27017)

在本地已经启动了 mongod 服务,使用其他工具可以连接上数据库。

执行了上面的两行代码后,出现了下面的报错信息

Exception in thread pymongo_server_monitor_thread:
Traceback (most recent call last):
  File "E:\python\Lib\threading.py", line 1052, in _bootstrap_inner
    self.run()
  File "E:\python\Lib\threading.py", line 989, in run
    self._target(*self._args, **self._kwargs)
  File "E:\python\Lib\site-packages\pymongo\periodic_executor.py", line 133, in _run    
    if not self._target():
           ^^^^^^^^^^^^^^
  File "E:\python\Lib\site-packages\pymongo\monitor.py", line 61, in target
    monitor._run()  # type:ignore[attr-defined]
    ^^^^^^^^^^^^^^
  File "E:\python\Lib\site-packages\pymongo\monitor.py", line 213, in _run
    self._start_rtt_monitor()
  File "E:\python\Lib\site-packages\pymongo\monitor.py", line 167, in _start_rtt_monitor
    self._rtt_monitor.open()
  File "E:\python\Lib\site-packages\pymongo\monitor.py", line 87, in open
    self._executor.open()
  File "E:\python\Lib\site-packages\pymongo\periodic_executor.py", line 95, in open     
    thread.start()
  File "E:\python\Lib\threading.py", line 971, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't create new thread at interpreter shutdown

大概是说 pymongo_server_monitor_thread 线程出现了异常,查了一下类似的问题,有的说是线程数太多,有的说是内存不足。但是我只执行了以上两行代码,内存也没发现什么飙升的情况。

这是什么原因导致的?
Python 3.12.0
pymongo 4.6.1
mongodb 7.0.4

阅读 984
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题