Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Debugger: "Timed out waiting for launcher to connect" #1677

Closed
MJ1Peter opened this issue Jun 8, 2024 · 34 comments
Closed

Python Debugger: "Timed out waiting for launcher to connect" #1677

MJ1Peter opened this issue Jun 8, 2024 · 34 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@MJ1Peter
Copy link

MJ1Peter commented Jun 8, 2024

Having an issue working in VSCode (Version: 1.90.0) using Python 3.12.2 on Mac. Program (below) runs just fine from the terminal:

Program

import sys

print (len(sys.argv))
print (sys.argv)
if  len(sys.argv) < 3:
    print("specify <sheet-name> <operation> where operation is 'create', 'insert', show' or 'delete'")
    sys.exit(1)
        
print("argument list:", str(sys.argv))
sheetname =  sys.argv[1]
operation =  sys.argv[2]

From terminal

petermelo@Peters-MacBook-Pro Code % python3 -V 
Python 3.12.2
petermelo@Peters-MacBook-Pro Code % python3 Test3.py 
1
['Test3.py']
specify <sheet-name> <operation> where operation is 'create', 'insert', show' or 'delete'
petermelo@Peters-MacBook-Pro Code % 

However, when I try to debug it from VSCode I get the following:
Image 6-8-24 at 10 19 AM

This is the config for launch.json im using:

`{

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [
          {
            "name": "Python Debugger: Current File (Integrated Terminal)",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
          }
]

}`

@MJ1Peter
Copy link
Author

MJ1Peter commented Jun 8, 2024

I would also add that this runs no problem on Linux.

@paulacamargo25
Copy link

Thanks for your bug report, could you send me the logs of the Python Debugger extension?

@MJ1Peter
Copy link
Author

@paulacamargo25
Copy link

Sorry for the delay in responding and thanks for the information, I will try to reproduce the bug.

@MJ1Peter
Copy link
Author

MJ1Peter commented Aug 6, 2024

Following back up on this, any update?

@paulacamargo25
Copy link

Thanks for reporting the bug, and sorry for the delay. I tried it on a Mac and it's working for me. Can you try again with the latest version of the Python Debugger extension and the latest version of VSCode? If the error persists, can you send me the Python Debugger output logs?

Copy link

Hey @karthiknadig, this issue might need further attention.

@MJ1Peter, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@ErideDLF
Copy link

ErideDLF commented Sep 11, 2024

I’m encountering a timeout issue when debugging Python tests in VSCode after updating to the latest version. My launch.json was working perfectly until a couple of days ago, but now it’s failing with the same timeout error.

Here’s the launch.json configuration I’m using:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Jira_id",
      "type": "debugpy",
      "request": "launch",
      "cwd": "${workspaceFolder}/_test/acceptance/src/",
      "module": "behave",
      "env": {
        "PYTHONPATH": "${workspaceFolder}/_test/acceptance/src"
      },
      "console": "integratedTerminal",
      "args": [
        "${file}",
        "-t",
        "@jira.${selectedText}",
        "--no-skipped",
        "-D",
        "TestExecution_environment=local_es"
      ],
      "stopOnEntry": false,
      "justMyCode": false,
      "logToFile": true
    }
  ]
}

The logs after attempting to execute are as follows:
debugpy.adapter-43236.log
debugger.vscode_a19536a8-b7ff-4432-865a-59075c481480.log

When running the following commands manually in the terminal, everything works fine:

behave /Users/cx02460/Documents/Development/wallet-core/_test/acceptance/src/features/api/0-component/01-transactions_api/014-operations_b2m/tasks/process_inactive_accounts_kyc/success.feature -t @jira.QAWLLT-2044 --no-skipped -D TestExecution_environment=local_es

python -m debugpy --listen 5678 -m behave /Users/cx02460/Documents/Development/wallet-core/_test/acceptance/src/features/api/0-component/01-transactions_api/014-operations_b2m/tasks/process_inactive_accounts_kyc/success.feature -t @jira.QAWLLT-2044 --no-skipped -D TestExecution_environment=local_es

However, when pointing to the debugpy launcher file, I get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/cx02460/.vscode/extensions/ms-python.debugpy-2024.11.2024082901-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/__main__.py", line 91, in <module>
    main()
  File "/Users/cx02460/.vscode/extensions/ms-python.debugpy-2024.11.2024082901-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/__main__.py", line 47, in main
    launcher.connect(host, port)
  File "/Users/cx02460/.vscode/extensions/ms-python.debugpy-2024.11.2024082901-darwin-arm64/bundled/libs/debugpy/launcher/../../debugpy/launcher/__init__.py", line 27, in connect
    sock.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused

I am completely stuck and unsure of the next steps to resolve this issue. Any assistance would be greatly appreciated.

@iliagerman
Copy link

Im also having the same timeout issue, not sure how to fix this

@goldengrisha
Copy link

A temporary fix can be a change in a launch.json: "console": "internalConsole".

@oscles
Copy link

oscles commented Sep 12, 2024

A temporary fix can be a change in a launch.json: "console": "internalConsole".

working for me

@MovingLive
Copy link

A temporary fix can be a change in a launch.json: "console": "internalConsole".

working for me too. Thanks!
@VSCodeTriageBot CodeIssue?

@BohdanKostivKrootl
Copy link

Hey, I'm having the same issue
Changing "console" configuration parameter to "internalConsole" or "externalTerminal" works
Seems like the Internal Terminal is the issue, hope to see it fixed, thanks!

@ErideDLF
Copy link

Thank you for your suggestion. I was able to get it working by setting "console": "internalConsole". This prevents the timeout error and opens the debug console, which is definitely an improvement. However, when I set breakpoints, the debugger only stops at some of them, and not others.

It's better than not being able to launch at all, but it’s still not a complete solution. I hope this can be resolved fully. Thanks again for your help!

@Lucashygi
Copy link

Lucashygi commented Sep 16, 2024

@ErideDLF, I'm encountering the same error. Everything worked fine until two weeks ago, but now it only works when setting "console": "internalConsole."
Unfortunately, the internal console is much less effective than the previous one.
This issue seems to be related to the Integrated Console, but it doesn't appear to be specific to the ZSH or Bash terminal on macOS.

I hope it gets fixed soon.

@nleroy917
Copy link

Also suddenly started having this issue about a week ago...

Unfortunately, the internal console is much less effective than the previous one.

I agree with this, and I also would really hope for a fix soon too.

@karthiknadig karthiknadig removed their assignment Sep 18, 2024
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python-debugger Sep 18, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 18, 2024
@iliagerman
Copy link

Any updates?

@TheJedinator
Copy link

Same issue for me changing to internalConsole works.

@josephkirankk
Copy link

Any updates ?

@nleroy917
Copy link

related? #1681

@neeox
Copy link

neeox commented Sep 23, 2024

Same issue for me, works with internalConsole as well.

@sirkozuch
Copy link

The issue is that the command is passed too early, before the terminal starts up, as mentioned in #1681.

As a work around, to make debugging work even with integratedTerminal option, you can copy the command and run it once again after the terminal starts up (usually 1-2s), but before the timeout message appears (after 15s).
Screenshot 2024-09-24 at 16 22 12

@rchiodo
Copy link
Contributor

rchiodo commented Sep 24, 2024

This seems like a vscode extension issue, not a debugpy issue. Debugpy doesn't pass the command to the terminal.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 24, 2024

@karthiknadig I think this would be a problem with the extension (or maybe VS code) running the command before the terminal starts up.

@karthiknadig
Copy link
Member

@rchiodo This is still with debugpy. This is the sequence of communication that occurs for a typical launch configuration.

There are 4 process involved.
P1 => VS Code
P2 => DAP (debugpy.adapter)
P3 => Debugpy launcher
P4 => User code with debug.server injected into it.

Sequence:

  1. User initiates a launce (by debug UI or Test UI).
  2. Python extension (in VS Code P1) generates the DAP configuration and starts the DAP server process P2. This type: launch configuration uses stdio for DAP communication.
  3. Then P1 and P2 go through the Initialization sequence. (see https://github.com/microsoft/debugpy/wiki/DAP-Client-reference#dap-implementation-details)
  4. After receiving the launch configuration. P2 opens a port and generates a command to return with run-in-terminal request with the port number. This is for the integratedTerminal console case. For other case P3 is launched directly by P2.
  5. VS Code P1 receives this command via run-in-terminal request, and creates a new terminal for debugging, and starts P3 from the terminal.
  6. P3 then connects back to P2. (<=== this is where the issue is occurring) as far as I can tell.
  7. After connecting P3 receives the User code details, like environment variables, and other config, like wait on exit, and launches user code with debug.server module injected into the process (P4).
  8. P4 Also connects back to P2. From this point, any subprocess started by P4 is also wired to communicate with P2. P2 acts as the main coordinator that receives commands from VS Code via DAP and it sends it across to P4 and any subprocesses.

I believe the issue occurs at 6. I am guessing something is going on with how the port is setting up.

The reason we need P3 and we don't directly launch P4 is to handle OS exit in Python. Typically, when python process exits we use sys.exit, and we can handle that with inproc debug server. But OS exist, does not allow us any opportunity to handle exit inproc.

Here is the code in P1 that starts P2:
https://github.com/microsoft/vscode-python-debugger/blob/afd0d2bbb634e51064806daa013fef5895d6c52e/src/extension/debugger/adapter/factory.ts#L38-L100

@mcrysler-ng
Copy link

Any updates?

@rchiodo
Copy link
Contributor

rchiodo commented Oct 1, 2024

We have yet to reproduce the problem. I still think it's some issue with VS code as debugpy doesn't change very often. You might try an older VS code and see if the problem goes away. That would be step 5 above. The 'run-in-terminal' message isn't starting the P3 process.

@Sube-py
Copy link

Sube-py commented Oct 8, 2024

It's finally fixed😄

1.94.0
d78a74bcdfad14d5d3b1b782f87255d802b57511
arm64

@jjwwczy
Copy link

jjwwczy commented Oct 9, 2024

Solved. I am using version 1.94.0 on Windows.

Right-click on Code.exe and select "Properties" from the context menu.
In the Properties window, switch to the "Compatibility" tab.
Uncheck the box that says "Run this program in compatibility mode for."
I found that my PC had this option checked. The problem was resolved after I unchecked it.

@rchiodo
Copy link
Contributor

rchiodo commented Oct 9, 2024

Closing giving that two people upgrading VS code solved the issue.

@rchiodo rchiodo closed this as completed Oct 9, 2024
@wabiloo
Copy link

wabiloo commented Oct 25, 2024

I still have the same issue on Mac, even with latest version...

@Sube-py
Copy link

Sube-py commented Oct 29, 2024

I still have the same issue on Mac, even with latest version...

Did you use conda?

@wabiloo
Copy link

wabiloo commented Oct 29, 2024

For what? But no, I've never used conda

@Sube-py
Copy link

Sube-py commented Nov 7, 2024

For what? But no, I've never used conda为了什么?但不,我从来没有使用过 conda

Because I found that when I disabled automatic activation of virtual environments, the problem disappeared and vscode automatically entered the command to activate virtual environments before the terminal launched successfully, causing debugpy to fail to launch. cc @rchiodo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests