Wait for a remote debugging client
import debugpy
debugpy.listen(5678)
print("Waiting for debugger attach")
debugpy.wait_for_client()
print("Debugger attached")
...
Or wait only when DEBUG
is set
import os
DEBUG = os.environ.get("DEBUG", False)
DEBUG_PORT = 5678
if DEBUG:
import debugpy
try:
debugpy.listen(DEBUG_PORT)
except RuntimeError as e:
print(f"Failed to listen on the debug port {DEBUG_PORT}: {e}")
else:
print("Waiting for debugger attach")
debugpy.wait_for_client()
print("Debugger attached")
...
- Make a debugging setting
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
]
}
]
}
- Set up break points
- Debug your python code