I have a Python project setup in VS Code. The Python project calls a C++ library, which I'd like to debug.
Normally, I'd debug as follows:
pytest
.The problem is that the last step shows more than one Python process (usually 3), all of which have been started by VS Code. Only one of them is the one I'm looking for (and will hit my C++ breakpoints), but I'm left to trial and error trying to find out which PID I'm after. VS Code does not tell me the relevant PID to attach to, and Visual Studio offers no additional details about the processes.
If I open up Process Explorer (from the Command Palette in VS Code), I am able to see the command line command that started the process as well as the process tree. From there, I'm able to guess the appropriate PID to attach to (ie the one where the --adapter-access-token
option was supplied on the command line).
Is there an easier way to determine the PID to attach to?
Thanks!
It looks like VS Code (as of version 1.70.3) does not show the PID in the debug windows (eg in the call stack window).
I've developed a simpler workaround for anyone interested.
.vscode/tasks.json
:{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Get target process ID",
"type": "shell",
"windows": {
"command": "PowerShell",
"args": [
"-File",
"${workspaceFolder}\\.vscode\\target_pid.ps1",
],
"options": {
"shell": {
"executable": "PowerShell.exe",
},
},
},
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new",
}
}
]
}
.vscode/target_pid.ps1
): Write-Information -MessageData "Locating python PIDs that can be attached to..." -InformationAction Continue
Get-WmiObject Win32_Process -Filter "name='python.exe' AND CommandLine LIKE '%--adapter-access-token%'" | select ProcessId, Path
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.