microsoft/ptvsd

Debug just hangs and does not seem to run Python file

paw-lu opened this issue · 12 comments

Environment data

  • VS Code version: 1.41.1
  • Extension version (available under the Extensions sidebar): 2020.2.64397
  • OS and version: macOS 10.14.4
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info microsoft/vscode-python#3977): Jedi
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

Debugger runs through the .py file.

Actual behaviour

The debugger just hangs at launch.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Create a .py file
print("hey")
a = "hi"
b = "bye"
print("hello")
  1. Create launch.json
{
  // 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: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "logToFile": true
    }
  ]
}
  1. Attempt to debug it

ezgif-3-d472ac34d7b0

Logs

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

Full debugger log

0 Starting Session:
{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "/Users/pcosta/Documents/scratch/install/test.py",
    "console": "integratedTerminal",
    "logToFile": true,
    "pythonPath": "/Users/pcosta/Documents/scratch/install/.venv/bin/python3",
    "cwd": "/Users/pcosta/Documents/scratch/install",
    "envFile": "/Users/pcosta/Documents/scratch/install/.env",
    "env": {
        "PYTHONIOENCODING": "UTF-8",
        "PYTHONUNBUFFERED": "1"
    },
    "stopOnEntry": false,
    "showReturnValue": true,
    "internalConsoleOptions": "neverOpen",
    "debugOptions": [
        "ShowReturnValue"
    ],
    "justMyCode": true,
    "workspaceFolder": "/Users/pcosta/Documents/scratch/install"
}
20 Client --> Adapter:
{
    "command": "initialize",
    "arguments": {
        "clientID": "vscode",
        "clientName": "Visual Studio Code",
        "adapterID": "python",
        "pathFormat": "path",
        "linesStartAt1": true,
        "columnsStartAt1": true,
        "supportsVariableType": true,
        "supportsVariablePaging": true,
        "supportsRunInTerminalRequest": true,
        "locale": "en-us"
    },
    "type": "request",
    "seq": 1
}
161 Client <-- Adapter:
{
    "seq": 1,
    "type": "event",
    "event": "output",
    "body": {
        "category": "telemetry",
        "output": "ptvsd",
        "data": {
            "packageVersion": "5.0.0a12"
        }
    }
}
162 Client <-- Adapter:
{
    "seq": 2,
    "type": "response",
    "request_seq": 1,
    "success": true,
    "command": "initialize",
    "body": {
        "supportsCompletionsRequest": true,
        "supportsConditionalBreakpoints": true,
        "supportsConfigurationDoneRequest": true,
        "supportsDebuggerProperties": true,
        "supportsDelayedStackTraceLoading": true,
        "supportsEvaluateForHovers": true,
        "supportsExceptionInfoRequest": true,
        "supportsExceptionOptions": true,
        "supportsHitConditionalBreakpoints": true,
        "supportsLogPoints": true,
        "supportsModulesRequest": true,
        "supportsSetExpression": true,
        "supportsSetVariable": true,
        "supportsValueFormattingOptions": true,
        "supportsTerminateDebuggee": true,
        "supportsGotoTargetsRequest": true,
        "exceptionBreakpointFilters": [
            {
                "filter": "raised",
                "label": "Raised Exceptions",
                "default": false
            },
            {
                "filter": "uncaught",
                "label": "Uncaught Exceptions",
                "default": true
            }
        ]
    }
}
164 Client --> Adapter:
{
    "command": "launch",
    "arguments": {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "/Users/pcosta/Documents/scratch/install/test.py",
        "console": "integratedTerminal",
        "logToFile": true,
        "pythonPath": "/Users/pcosta/Documents/scratch/install/.venv/bin/python3",
        "cwd": "/Users/pcosta/Documents/scratch/install",
        "envFile": "/Users/pcosta/Documents/scratch/install/.env",
        "env": {
            "PYTHONIOENCODING": "UTF-8",
            "PYTHONUNBUFFERED": "1"
        },
        "stopOnEntry": false,
        "showReturnValue": true,
        "internalConsoleOptions": "neverOpen",
        "debugOptions": [
            "ShowReturnValue"
        ],
        "justMyCode": true,
        "workspaceFolder": "/Users/pcosta/Documents/scratch/install",
        "__sessionId": "93c292c0-e4f5-4965-8eca-8b1368ce32c4"
    },
    "type": "request",
    "seq": 2
}
166 Client <-- Adapter:
{
    "seq": 3,
    "type": "request",
    "command": "runInTerminal",
    "arguments": {
        "kind": "integrated",
        "title": "Python Debug Console",
        "args": [
            "/Users/pcosta/Documents/scratch/install/.venv/bin/python3",
            "/Users/pcosta/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher",
            "/Users/pcosta/Documents/scratch/install/test.py"
        ],
        "env": {
            "PTVSD_LAUNCHER_PORT": "65275",
            "PTVSD_LOG_DIR": "/Users/pcosta/.vscode/extensions/ms-python.python-2020.2.64397"
        }
    }
}
822 Client --> Adapter:
{
    "type": "response",
    "seq": 3,
    "command": "runInTerminal",
    "request_seq": 3,
    "success": true,
    "body": {
        "shellProcessId": 29729
    }
}
3687 Client <-- Adapter:
{
    "seq": 4,
    "type": "event",
    "event": "initialized"
}
3695 Client --> Adapter:
{
    "command": "setBreakpoints",
    "arguments": {
        "source": {
            "name": "test.py",
            "path": "/Users/pcosta/Documents/scratch/install/test.py"
        },
        "lines": [
            3
        ],
        "breakpoints": [
            {
                "line": 3
            }
        ],
        "sourceModified": false
    },
    "type": "request",
    "seq": 4
}
3698 Client <-- Adapter:
{
    "seq": 5,
    "type": "response",
    "request_seq": 4,
    "success": true,
    "command": "setBreakpoints",
    "body": {
        "breakpoints": [
            {
                "verified": true,
                "id": 0,
                "source": {
                    "name": "test.py",
                    "path": "/Users/pcosta/Documents/scratch/install/test.py"
                },
                "line": 3
            }
        ]
    }
}
3708 Client --> Adapter:
{
    "command": "setExceptionBreakpoints",
    "arguments": {
        "filters": [
            "uncaught"
        ]
    },
    "type": "request",
    "seq": 5
}
3710 Client <-- Adapter:
{
    "seq": 6,
    "type": "response",
    "request_seq": 5,
    "success": true,
    "command": "setExceptionBreakpoints"
}
3713 Client --> Adapter:
{
    "command": "configurationDone",
    "type": "request",
    "seq": 6
}
3715 Client <-- Adapter:
{
    "seq": 7,
    "type": "response",
    "request_seq": 6,
    "success": true,
    "command": "configurationDone"
}
3715 Client <-- Adapter:
{
    "seq": 8,
    "type": "response",
    "request_seq": 2,
    "success": true,
    "command": "launch"
}
3715 Client <-- Adapter:
{
    "seq": 9,
    "type": "event",
    "event": "process",
    "body": {
        "startMethod": "launch",
        "isLocalProcess": true,
        "systemProcessId": 29854,
        "name": "/Users/pcosta/Documents/scratch/install/test.py",
        "pointerSize": 64
    }
}
3716 Client --> Adapter:
{
    "command": "threads",
    "type": "request",
    "seq": 7
}

I have that problem too. Also on mac. The strange thing is that sometimes it works and sometimes not.

Yeah! After messing with it more it seems to work for me maybe ~15% of the time. Though I'm yet unable to find out what triggers it. Have tested multiple Python versions and environments. Let me know if you come across something useful!

We'll need some logs to diagnose this. Can you please add "logToFile": true to your config in launch.json, and try to reproduce it again? The log files will be in the directory where the extension is installed, with names matching ptvsd.*.log.

Hey @int19h !

Is the log I provided not the right one (it's collapsed)?

It's slightly different - this log is of the IDE interacting with the debugger, but the one you'll get from "logToFile" is from the debugger itself.

Strange. I have activate logToFile but now the problem does not occur 🤔. I will add the log when it happens again.

@pscosta5 Can you reproduce the problem today when you activate the logToFile switch in launch.json?

Things I discovered when I saw the problem

For me it seems that the problem is the virtualenv activation because it always works when the venv is activate via vscode at the first time. When the venv was activated (by vscode) it seems that sometimes it is waiting for the activation but it wait's forever.

@int19h Thanks for the explanation!

You may find the requested log below!

ptvsd.server-52773.log

@pscosta5, was it the only log that starts with "ptvsd" there? There should also be ptvsd.adapter...log and ptvsd.launcher...log.

ptvsd.launcher-52769.log
ptvsd.adapter-52635.log

@int19h You're correct! Apologies for the oversight.

I wasn't 100% sure those logs were correlated with each other, so I've generated a new trio just in case

ptvsd.adapter-869.log
ptvsd.launcher-1145.log
ptvsd.server-1149.log

My apologies for a belated follow-up!

The logs don't show anything unusual, except that the process never really exits. I wonder what happens if you hit Pause (F6) on the debug toolbar - it should hopefully break somewhere...

@int19h No need to apologize!

Revisited this issue today, and now I am unable to reproduce—the debugger is now working as expected. Updates may have changed something.

I'll close for now and reopen when I can reproduce.