microsoft / vscode-python-debugger

Python debugger (debugpy) extension for VS Code.
https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy
MIT License
57 stars 24 forks source link

Unknown characters were output in the built-in terminal. #302

Closed ZhanZiyuan closed 4 months ago

ZhanZiyuan commented 6 months ago

Behaviour

Debug a Python file C:\Users\user\Downloads\test.py in Visual Studio Code.

Steps to reproduce:

  1. Open C:\Users\user\Downloads\test.py in Visual Studio Code.

  2. Press F5.

  3. The built-in terminal launched.

  4. The output is printed, while it looks strange:

    ❯  & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '55162' '--' 'C:\Users\user\Downloads\test.py' 
    y' ;f32e748c-078e-4722-b78a-88d04fc76110y' ;f32e748c-078e-4722-b78a-88d04fc761107.098666746304519
  5. However, if the Python file is run in the terminal instead of being debugged with Visual Studio Code, the issue will not occur:

    ❯ python C:\Users\user\Downloads\test.py
    7.098666746304519

Diagnostic data

launch.json configuration

```json { "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true }, { "name": "C/C++: gcc.exe 生成和调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "C/C++: gcc.exe 生成活动文件" } ] } ```

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

```log 2024-04-05 20:11:01.495 [info] DAP Server launched with command: D:\Python\python.exe c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter 2024-04-05 20:11:03.265 [info] Send text to terminal: & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '55037' '--' 'C:\Users\user\Downloads\test.py' ```

Output for Python Debugger in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Debugger)

```log Nothing. ```

2024-04-05_20-52-08

karthiknadig commented 6 months ago

@ZhanZiyuan Can you share logs from Output > Python? this seems like it might be coming from python extension trying to activate the environment.

ZhanZiyuan commented 5 months ago

@ZhanZiyuan Can you share logs from Output > Python? this seems like it might be coming from python extension trying to activate the environment.

OK. Here are logs from Output > Python:

Output for Python in the Output panel Contents in brackets were translated by Google Translate. ```text 2024-04-06 09:09:48.404 [info] 试验“pythonRecommendTensorboardExt”处于活动状态 (Test "pythonRecommendTensorboardExt" is active) 2024-04-06 09:09:48.404 [info] 试验“pythonREPLSmartSend”处于活动状态 (Test "pythonREPLSmartSend" is active) 2024-04-06 09:09:48.404 [info] 试验“pythonTerminalEnvVarActivation”处于活动状态 (Test "pythonTerminalEnvVarActivation" is active) 2024-04-06 09:09:48.404 [info] 试验“pythonTestAdapter”处于活动状态 (Test "pythonTestAdapter" is active) 2024-04-06 09:09:48.404 [info] Default formatter is set to ms-python.black-formatter for workspace d:\zigzag\Python Assignments 2024-04-06 09:09:48.404 [info] Default formatter is set to ms-python.black-formatter for workspace d:\zigzag\postgraduate\curricula\computational chemistry\assignments 2024-04-06 09:09:48.404 [info] Test server listening. 2024-04-06 09:09:48.404 [info] Python 解释器路径: D:\Python\python.exe (Python interpreter path: D:\Python\python.exe) 2024-04-06 09:09:51.325 [info] > conda info --json 2024-04-06 09:09:51.327 [info] DAP Server launched with command: D:\Python\python.exe c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter 2024-04-06 09:09:55.800 [info] 正在启动 Pylance 语言服务器。 (Launching Pylance language server.) 2024-04-06 09:10:37.285 [info] > ~\.conda\Scripts\conda.exe info --json 2024-04-06 09:10:37.380 [info] > ~\.condarc\Scripts\conda.exe info --json 2024-04-06 09:10:37.469 [info] > D:\Miniconda3\Scripts\conda.exe info --json 2024-04-06 09:10:37.810 [info] > hatch env show --json 2024-04-06 09:10:37.810 [info] cwd: D:\zigzag\Python Assignments 2024-04-06 09:10:37.810 [info] > hatch env show --json 2024-04-06 09:10:37.810 [info] cwd: D:\zigzag\postgraduate\curricula\computational chemistry\assignments 2024-04-06 09:10:37.830 [info] > D:\Python\python.exe -I ~\.vscode\extensions\ms-python.python-2024.4.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.4.0\python_files\interpreterInfo.py 2024-04-06 09:11:32.259 [info] Send text to terminal: & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '61783' '--' 'C:\Users\user\Downloads\test.py' 2024-04-06 09:13:34.460 [info] DAP Server launched with command: D:\Python\python.exe c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter 2024-04-06 09:13:35.019 [info] Send text to terminal:  2024-04-06 09:13:35.019 [info] Send text to terminal: d:; cd 'd:\zigzag\Python Assignments'; & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '62042' '--' 'C:\Users\user\Downloads\test.py' ```

I found that when switching between Output and Terminal, what's printed in Terminal occasionally becomes normal:

Incorrect output in the built-in terminal ```bash ❯ d:; cd 'd:\zigzag\Python Assignments'; & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '62282' '--' 'C:\Users\user\Downloads\test.py' 2' '--' 'C:\x5cUsers\x5cuser\x5cDownloads\x5ctest.py' ;d089afb6-7948-4b04-9449-756ef89608562' '--' 'C:\x5cUsers\x5cuser\x5cDownloads\x5ctest.py' ;d089afb6-7948-4b04-9449-756ef89608567.098666746304519 ```
Correct output in the built-in terminal ```bash ❯ d:; cd 'd:\zigzag\Python Assignments'; & 'D:\Python\python.exe' 'c:\Users\user\.vscode\extensions\ms-python.python-2024.4.0\python_files\lib\python\debugpy\adapter/../..\debugpy\launcher' '62042' '--' 'C:\Users\user\Downloads\test.py' 7.098666746304519 ```
veroneoriginal commented 5 months ago

Good afternoon! I have the same problem. When running the script, the "c" character gets into the terminal, then an error occurs and then the script is executed. shot_240406_142435

ferihegedus commented 5 months ago

I have the same problem. Some additional info: for the first time that the "Python Debug Console" terminal window is launched, the script is started and the debug session works. However, if I want to debug again, it does not work in Git Bash, and behaves strangely in PowerShell.

Output in GitBash First try: image

Second try: image

Output in PowerShell First try: image

Second try: image

EDIT: There are no issues with version 1.87.2.

karthiknadig commented 5 months ago

@Tyriar This looks like it might be coming from shell integration.

Tyriar commented 5 months ago

@karthiknadig that guid could be the set command line nonce if it's not something the extension is inputting 🤔

@ZhanZiyuan what version of Windows are you on?

ZhanZiyuan commented 5 months ago

@karthiknadig that guid could be the set command line nonce if it's not something the extension is inputting 🤔

@ZhanZiyuan what version of Windows are you on?

Hello. My OS Version: Windows 10.0.19045

I'm also using the latest stable release of Visual Studio Code (version 1.88).

Tyriar commented 5 months ago

This is likely a very old version of conpty misbehaving as it's shipped with Windows and you're still on 10. So a workaround is to disable shell integration, the real fix is to update to Windows 11.

ZhanZiyuan commented 5 months ago

This is likely a very old version of conpty misbehaving as it's shipped with Windows and you're still on 10. So a workaround is to disable shell integration, the real fix is to update to Windows 11.

Alright, many thanks for your reply though the computer is not eligible to upgrade to Windows 11.

ferihegedus commented 5 months ago

This is likely a very old version of conpty misbehaving as it's shipped with Windows and you're still on 10. So a workaround is to disable shell integration, the real fix is to update to Windows 11.

I have this problem on Windows 11 as well. However it might be independent of the Python Debugger itself, as there are no issues with VsCode version 1.87.2, only with 1.88.

The problem is only present when using "console": "integratedTerminal".

yezy98 commented 5 months ago

I have encountered similar issue when I update to VSC 1.88.1 and it is solved when I revert to 1.87.2 When I debug a Python file, for the first time, everything works normally. However, if I restart it or stop and debug again, it goes wrong. Although from the Outoput, I can see the command text is sent to Terminal, there is no text shown on the Terminal. Seconds later, a TimeOut error raised.

Another walkaround is setting "console" as "internal Console" in launch.json

My Windows version is 22631.3527

I have another PC with a Windows Canary Insider Preview 26200.5001 And VSC 1.88.1 works well.

paulacamargo25 commented 4 months ago

Closing the issue as the error is on vscode side.