win10+wsl2+pycharm2021 Debug: socket.timeout: timed out

在run运行模式下可以正常跑,但是不能debug

报错如下:

C:\Windows\system32\wsl.exe
....
Could not connect to 172.17.192.1: 49429
Traceback (most recent call last):
  File "/mnt/d/JetBrains/PyCharm 2021.2.3/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 458, in start_client
    s.connect((host, port))
socket.timeout: timed out
Traceback (most recent call last):
  File "/mnt/d/JetBrains/PyCharm 2021.2.3/plugins/python/helpers/pydev/pydevd.py", line 2173, in <module>
    main()
  File "/mnt/d/JetBrains/PyCharm 2021.2.3/plugins/python/helpers/pydev/pydevd.py", line 2055, in main
    dispatcher.connect(host, port)
  File "/mnt/d/JetBrains/PyCharm 2021.2.3/plugins/python/helpers/pydev/pydevd.py", line 1826, in connect
    self.client = start_client(self.host, self.port)
  File "/mnt/d/JetBrains/PyCharm 2021.2.3/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 458, in start_client
    s.connect((host, port))
socket.timeout: timed out

Process finished with exit code 1

原因:win10没有打开防火墙

解决方式:

reference: 

python - WSL 2 : Pycharm debugger connection time out - Stack Overflow

https://youtrack.jetbrains.com/issue/PY-36563#focus=streamItem-27-3745830.0-0

Run PowerShell as Administrator, and do (assume that Ubuntu1804 is your WSL2 distro):
PS C:\WINDOWS\system32> $myIp = (Ubuntu1804 run "cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2")
PS C:\WINDOWS\system32> $myIp
172.21.0.1
PS C:\WINDOWS\system32>  New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -LocalAddress $myIp -Action AllowSee https://github.com/microsoft/WSL/issues/4585

See Add "allow" rule to Windows firewall for WSL2 network · Issue #4585 · microsoft/WSL · GitHub

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值