Ray Debug Tutorial
Author: Ao Shen.
How to debug?
Ray Distributed Debugger VSCode Extension (Recommended)
Starting with Ray 2.39, Anyscale has introduced the Ray Distributed Debugger VSCode extension. Follow the extension’s installation instructions, then add your cluster using the dashboard URL you obtained earlier.
Prerequisites.
Ensure the following are installed (see the extension README for more detail):
Visual Studio Code
ray[default] >= 2.9.1
debugpy >= 1.8.0
Environment Variables.
To enable post‑mortem debugging, set:
export RAY_DEBUG_POST_MORTEM=1
Note
Be sure to remove any legacy flags before starting Ray:
RAY_DEBUG=legacy
–ray-debugger-external
Configuring BreakpointsSet up breakpoint() in your code, and submit job to cluster. Then the extension will show the breakpoint information.
Insert breakpoint() calls into your remote functions.
Submit your job to the cluster.
The extension will detect active breakpoints and display them in VSCode.
Note: Breakpoints are only supported inside functions decorated with @ray.remote.
Launching the Debugger.
Run your job directly from the command line (do not use a launch.json):
python job.py
Attaching to a Breakpoint.
Once the process hits the first breakpoint(), click the Ray Distributed Debugger icon in the VSCode sidebar to attach the debugger.
![]()
Debugging With Multiple breakpoint().
For each subsequent task, first disconnect the current debugger session, then click the extension icon again to attach to the next breakpoint.
Legacy Ray Debugger
Ray has a builtin legacy debugger that allows you to debug your distributed applications. To enable debugger, start ray cluster with
RAY_DEBUG=legacy
and--ray-debugger-external
.
# start head node
RAY_DEBUG=legacy ray start --head --dashboard-host=0.0.0.0 --ray-debugger-external
# start worker node
RAY_DEBUG=legacy ray start --address='10.124.46.192:6379' --ray-debugger-external
Set up breakpoint in your code, and submit job to cluster. Then run
ray debug
to wait breakpoint:
