Quick Debug with VSCode and debugpy

Need to debug a random python process?


  1. Add the code below where you wanna break.
  2. Start the process with the debugpy modoule
  3. Use VSCode to connect to listening debugger

1 Add Code

def somefunction():
    # add this
    import debugpy
    print("Opening debug connection on port 5678 and waiting...")
    debugpy.breakpoint() # optional?

2 Start the process

python -m debugpy --listen 5678 ./manage.py migrate wayapi
              ^              ^        ^               
              install if required                             
                             default port
                                      script and arguments

* Sometimes add the option: python -Xfrozen_modules=off

3 Connect with VSCode

In run and debug, select the dropdown and choose “python debugger: remote attach”

image 41
image 41

Leave a Reply

Your email address will not be published. Required fields are marked *