问题背景以及问题描述:
在debug 过程中,出现了 Connection to Python debugger failed Socket closed 错误具体报错为:
Traceback (most recent call last):
File "/home/Downloads/pycharm-community-2022.3.1/plugins/python-ce/helpers/pydev/pydevd.py", line 45, in <module>
from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO, CMD_STEP_OVER, \
File "/home/Downloads/pycharm-community-2022.3.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 91, in <module>
from _pydevd_bundle import pydevd_console_integration
File "/home/Downloads/pycharm-community-2022.3.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 21, in <module>
from _pydevd_asyncio_util.pydevd_nest_asyncio import apply
File "/home/Downloads/pycharm-community-2022.3.1/plugins/python-ce/helpers/pydev/_pydevd_asyncio_util/pydevd_nest_asyncio.py", line 33, in <module>
import asyncio
File "/home/anaconda3/envs/pyslowfast/lib/python3.10/asyncio/__init__.py", line 8, in <module>
from .base_events import *
File "/home/anaconda3/envs/pyslowfast/lib/python3.10/asyncio/base_events.py", line 18, in <module>
import concurrent.futures
File "/home/anaconda3/envs/pyslowfast/lib/python3.10/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/home/anaconda3/envs/pyslowfast/lib/python3.10/concurrent/futures/_base.py", line 7, in <module>
import logging
File "/home/PYTHON-PROJ/Contrast_learing/SAIC_MAEST/util/logging.py", line 12, in <module>
import torch
File "/home/anaconda3/envs/pyslowfast/lib/python3.10/site-packages/torch/__init__.py", line 457, in <module>
for name in dir(_C):
NameError: name '_C' is not definedProcess finished with exit code 1
因此下意识我想run它(省略写)依然有错误 ,那么先解决 run 的问题:
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)Process finished with exit code 1
解决过程及问题成因:
看到问题的核心是(most likely due to a circular import) 即为一个 循环的引用
那么大概率就是logging 这个模块有 循环引用
果然文件同路径下有 logging.py 并且 在 logging.py 中 还 import 了 logging,造成了循环引用
解决方案:
更改 名字 避免循环引用:
把原logging.py 更名为logging1.py
即可解决问题文章来源:https://www.toymoban.com/news/detail-772921.html
结论及重点:
造成 Connection to Python debugger failed Socket closed 的原因会有很多,需要具体去看错误,循序渐进即可解决,在本例(most likely due to a circular import)中造成该情况的原因则是循环引用文章来源地址https://www.toymoban.com/news/detail-772921.html
到了这里,关于解决 Connection to Python debugger failed Socket closed 及 (most likely due to a circular import) 问题处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!