Can't run Debugger - 'Connection to Python debugger failed; Socket closed'

已回答

I've been trying to get the debugger to work on a remote work station but I keep having this error pop up when trying to debug a code/script. Interestingly enough, when I run my scripts normally, I my codes execute without issue, but I really need the debugging tool when creating other scripts. I have tried creating a brand new projects but when I run the debugger again, I have this error pop up.

/mnt/home/jpsc230/anaconda3/envs/rcrest19/bin/python /mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 45959 --file /hd2/work/jon/py/pythonProject/rcrest19/test_debugging_rcrest19.py
Traceback (most recent call last):
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_trace_dispatch.py", line 55, in <module>
from _pydevd_bundle.pydevd_cython_wrapper import trace_dispatch as _trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_cython_wrapper.py", line 48, in <module>
raise exc
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/pydevd.py", line 49, in <module>
from _pydevd_bundle.pydevd_trace_dispatch import (
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_trace_dispatch.py", line 63, in <module>
delete_old_compiled_extensions()
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_trace_dispatch.py", line 19, in delete_old_compiled_extensions
cython_extensions_dir = os.path.dirname(os.path.dirname(_pydevd_bundle_ext.__file__))
File "/mnt/home/jpsc230/anaconda3/envs/rcrest19/lib/python3.8/posixpath.py", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Process finished with exit code 1

 

 

I have seen other people that had issues with "Socket closed" errors, but usually those instances were resolved with renaming/deleting a script/code they had named 'code.py' or something to that effect. I don't believe that is the issue here. Any help or direction is greatly appreciated.

 

2

Hi,

The issue seems to be the same as https://youtrack.jetbrains.com/issue/PY-44558, which is not fixed yet.

Does it help if you add PYDEVD_USE_CYTHON=NO environment variable to your run configuration (Run | Edit Configurations...)?


If not, try the workaround from this comment https://youtrack.jetbrains.com/issue/PY-44558#focus=Comments-27-4485084.0-0

1

Adding ;PYDEVD_USE_CYTHON=NO to the configuration seems to have been a sufficient work around. Is there way to set this as a sort of 'default' for a project? I'm assuming this is an error that will be addressed in future releases of Pycharm? Thanks for the help by the way! Sorry to post a redundant instance.

0

Sure, you can add it to the run configuration template. Each new run config will have it by default, but you still need to add it to the existing ones.

Yes, we'll fix it for sure, but I can't provide you with ETA yet.

2

Hi,

I'm trying to debug within pytest. Adding `PYDEVD_USE_CYTHON=NO` to the configuration stops the socket crashing, but the debugger is broken. Stepping into code takes me into pytest code rather than my application code. Will take a lot of time for me to rewrite fixtures to debug outside of pytest.

1

Peter Goodall

Could you please submit an issue to https://youtrack.jetbrains.com/issues/py with the code sample and steps to reproduce?

0

Thanks, Sergey Karpov! The photo helped me to fix the issue.

0

i moved my files to primary location of pycharm and debugging works!!

before that my files was on personal location that i made .

0

I face this issue always in PyCharm as  ‘Connection to Python debugger failed : Socket closed’
I tried changing the environment variable to PYDEVD_USE_CYTHON=NO
Still faced the same issue
And tried changing the environment variable to PYTHONUNBUFFERED=1
Still faced the same issue
I face the below error in console after debugging the code .


"C:\Program Files\Python311\python.exe" "C:/Users/Sekar/PyCharm Community Edition 2023.2.1/plugins/python-ce/helpers/pydev/pydevd.py" --multiprocess --save-signatures --client 127.0.0.1 --port 50986 --file C:\Users\Sekar\PycharmProjects\Pythonsept\firstprog.py 
Traceback (most recent call last):
  File "C:\Users\Sekar\PyCharm Community Edition 2023.2.1\plugins\python-ce\helpers\pydev\pydevd.py", line 40, in <module>
    import pydevd_tracing
  File "C:\Users\Sekar\PyCharm Community Edition 2023.2.1\plugins\python-ce\helpers\pydev\pydevd_tracing.py", line 1, in <module>
    import ctypes
  File "C:\Program Files\Python311\Lib\ctypes\__init__.py", line 163, in <module>
    _check_size(py_object, "P")
  File "C:\Program Files\Python311\Lib\ctypes\__init__.py", line 153, in _check_size
    raise SystemError("sizeof(%s) wrong: %d instead of %d" % \
SystemError: sizeof(<class 'ctypes.py_object'>) wrong: 8 instead of 0

I tried unticking PyQT compatibility also in Python Debugger and still face the issue for debugging.


Please anyone help me with further recoveries please

0

Siddhusir23 It seems the issue happens when importing ctypes. Please try running Python from “C:\Program Files\Python311” and execute “import ctypes”. Does it work?

0

Yeah its not working and throws the same system error.
Program is running from C:ProgramFiles\Python311\python.exe
But still face this ctype error.





any environment variable to change please let me know.
Can you please help me with this ctypes part and how to resolve on this

0
Well, it looks like a python issue. Please try reinstalling it from https://www.python.org
0

Working for me: delete the Path in Working directory of your run/debug configuration

1

Still facing the same issue on Idea CE : 'Connection to Python debugger failed; Socket closed'

0

For me it worked after reinstalling / restarting Pycharm with New Project. 
Try running Py in Virtual Environment.
Thanks !

0
A socket closed error usually signifies that the socket is already in use in the system. Rebooting the system might be helpful in most cases.
Also, removing the run configuration for your file (Run | Edit Configurations) and regenerating it again by running a file with the default run config might be helpful.
0

请先登录再写评论。