Debugging Prefect Flows with breakpoints. Hello f...
# prefect-community
Debugging Prefect Flows with breakpoints. Hello friends. I love coding Python in VSCode, the debugging with breakpoints make me so efficient. But the debugging fun stops with Prefect Flows, when we initialize them from CLI:
Copy code
$ prefect run --path --log-level INFO --param myparam=val
Here the development flow becomes rather blackboxed/trial-and-error. Is it possible to somehow set breakpoints in VSCode, start a prefect flow from CLI, and attach the debugger to the python process? (Running with the LocalExecutor)
discourse 1
@Kevin Mullins... your useful just answer disappeared?
Yes this is possible. You should just be able to add a new python launch configuration with prefect run command and arguments. Another option is to add a call to in your flow and using the debug current file feature.
upvote 1
Sorry, I realized I gave the wrong info first, was clarifying
For the example of calling, some people use a main guard for debugging/running, here is an example that would work with debug current file:
Copy code
import prefect
from prefect import task, Flow

def say_hello():

with Flow("test-debug") as flow:

if __name__ == "__main__":
Oh yes, I was using a small pytest file with[params]) but the main guard is also nice.
Here is an example launch config if you wanted to go that route (for instance if you didn’t want the main guard)
Copy code
  "name": "Python: Flow Debug Example",
  "type": "python",
  "request": "launch",
  "program": "${workspaceFolder}/.venv/bin/prefect",
  "args": [
  "console": "integratedTerminal",
  "justMyCode": true
👍 2
I think the launch config has the upside to be able to show info/debug logs to the terminal. Or is it also possible with the debug method?
Both of them should show them, vs code should create a python debug terminal
🙌 1
@Kevin Mullins thanks a lot, both works great. Launch config is a bit clunkly because prefect is installed with pipenv:
program": "/home/[USER]/.local/share/virtualenvs/[SOURCEFOLDER]-[HASH]/bin/prefect",