https://dagster.io/ logo
Title
m

Mark

04/20/2021, 12:00 AM
Hi again, one more thing i am trying to figure out: Does someone have a hint how to debug with the VSCode debugger when running a pipeline via dagit? I am new to python and the best option i came up with so far is to use debugpy in a solid, but that only works if i start listening in the solid itself. Is there a better way to initialize debugpy globally and be able to set breakpoints in multiple solids to attach via VSCode debugger and then debug a whole pipeline?
r

rex

04/20/2021, 5:14 AM
Hey Mark - here’s my
launch.json
configuration to attach the vscode debugger to the dagit process
{
        "name": "Debug Dagit",
        "type": "python",
        "request": "launch",
        "module": "dagit",
        "cwd": "${workspaceFolder}",
        "args": [
                "-w",
                "your/workspace/path/workspace.yaml"
        ],
        "console": "integratedTerminal",
}
you can learn more about the settings here: https://code.visualstudio.com/docs/editor/debugging
once this is set up, then breakpoints in your user code (i.e. your solids and pipelines) will halt execution in dagit until they are stepped over, continued, etc
m

Mark

04/20/2021, 10:08 AM
Thanks a lot!
Hi again. How do you manage reloads with that setup? Seems like the VSCode debuggers reload button will not reload/restart dagit, right?
Okay got it, i guess just keep the debugger running and reload dagit via repo reload button.
a

alex

04/20/2021, 2:39 PM
I believe you will want to include
"subProcess": true
in the config section since
dagit
will use subprocess for interacting with your code and running pipelines
m

Mark

04/24/2021, 2:27 PM
Hi, should this approach work for debugging sensor code or only for solids?
a

alex

04/26/2021, 3:23 PM
the sensor evaluation runs subprocess to the
dagster-daemon
so you would have to run that in a debugger which is not as simple since its not its own python module
cc @daniel & @prha incase they know how to get the sensor captured in a debugger
m

Mark

05/01/2021, 10:13 AM
Is the sensor also running as a subprocess when launched via
dagster sensor preview
? If not it should be possible to at least attach the debugger to a separate sensor launched that way, right?
And maybe you have an idea how to prevent a PYDEV DEBUGGER WARNING i am getting when running in the debugger: "sys.settrace() should not be used when the debugger is being used"
p

prha

05/04/2021, 4:27 PM
@Mark does it work for you to change your sensor code to call
pdb.set_trace()
and then run
dagster sensor preview <sensor_name>
?
m

Mark

05/09/2021, 1:25 PM
Hi @prha - i am not sure yet how extensive i will need to debug sensors, so i'll try if this approach to debug without breakpoints works for me. Thanks for the hint.
So, technically this works. As i am new to python i am not used to pdb. Is there a way to attach the VSCode Debugger to
dagster sensor preview...
that would be great.
a

alex

05/10/2021, 2:51 PM
a debugger entry like this should work
{
            "name": "dagster sensor",
            "type": "python",
            "request": "launch",
            "module": "dagster",
            "args": [
                "sensor",
                "preview",
                // other args here
            ]
        },
a

Aaron Hoffer

05/02/2022, 5:29 PM
Is this still a valid way to do debugging VSCode? This is my launch.json and it isn’t stopping on breakpoints. I’m running
DAGSTER_HOME=/Users/aaron/dagster_home/ dagster-daemon run --python-file repo.py
in a separate shell.
{
      "name": "Debug Dagit",
      "type": "python",
      "request": "launch",
      "module": "dagit",
      "cwd": "${workspaceFolder}/pipeline",
      "env": {
        "DAGSTER_HOME":"/Users/aaron/dagster_home/"
      },
      "args": [
              "-f",
              "repo.py"
      ],
      "console": "integratedTerminal",
      "subProcess": true
a

alex

05/02/2022, 5:34 PM
try
"justMyCode": false
a

Aaron Hoffer

05/02/2022, 5:41 PM
Still doesn’t stop unfortunately. I’m triggering the job from a sensor, but the breakpoints are in the ops, not the sensor.
k

Keith Gross

05/02/2022, 5:42 PM
This worked for me recently:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Dagit",
      "type": "python",
      "request": "launch",
      "module": "dagit",
      "cwd": "${workspaceFolder}",
      "args": [
        "-f",
        "repo.py"
      ],
      "console": "integratedTerminal"
    }
  ]
}
a

alex

05/02/2022, 5:47 PM
I’m triggering the job from a sensor
this goes through the daemon which doesn’t route anything through dagit, in the local case it has its own subprocess grpc server
options then are: • run daemon via vscode • use
dagster sensor preview
shown earlier in this thread • manually run the grpc server (via vscode) and change your workspace to point that directly • try to reproduce in a test context https://docs.dagster.io/concepts/partitions-schedules-sensors/sensors#testing-sensors
👀 1
a

Aaron Hoffer

05/02/2022, 6:07 PM
use
dagster sensor preview
shown earlier in this thread
This worked, but only with breakpoints within the sensor
run daemon via vscode
Not sure what you mean by this, from above it sounded like you can’t run a debugger on the daemon itself. I’d also be ok using
breakpoint()
in places but that just causes the job to error when run.
a

alex

05/02/2022, 6:35 PM
stepping back, if you have the run config the sensor is submitting you can use the op/job testing APIs to directly execute in process https://docs.dagster.io/concepts/testing#testing
a

Aaron Hoffer

05/02/2022, 6:48 PM
Oh, perfect, thanks!