https://pulumi.com logo
#python
Title
# python
a

average-school-38756

09/16/2020, 7:32 PM
Anyone have a working VS Code debugging implementation for code run by the CLI? Hoping someone can spot the issue in mine. Inspired by https://github.com/pulumi/pulumi/issues/1372#issuecomment-583086422 i set up a
.vscode/launch.json
looking like this:
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Attach using Process ID",
      "type": "python",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ]
}
i put this code at the beginning of my
___main___.py
, with a breakpoint as a sanity check (and i have a VS Code breakpoint on the same line):
Copy code
import debugpy
debugpy.listen(5678)
debugpy.wait_for_client()
debugpy.breakpoint()
i run
pulumi up
which shows this output (appears as though
wait_for_client
is indeed working):
Copy code
$ pulumi up
Previewing update (dev):
And i hit F5 to trigger the process attachment. i choose the process called "pulumi up" in the dialog. After ten seconds or so, i get a prompt in VS Code saying "Timed out waiting for debug server to connect."
Might have been a timing issue. Here's how i resolved it using a reverse connection (https://devblogs.microsoft.com/python/python-in-visual-studio-code-july-2020-release/):
.vscode/launch.json
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Attach using listen",
      "type": "python",
      "request": "attach",
      "listen": {
        "host": "127.0.0.1",
        "port": 5678
      }
    }
  ]
}
and in `___main___.py`:
Copy code
import debugpy
debugpy.connect(('localhost', 5678))
With this method, you start the debugger before running
pulumi up
.
30 Views