Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 4921e53

Browse files
committed
Update images and address feedback
1 parent 747f255 commit 4921e53

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

docs/guides/python/debugging.mdx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ This guide will walk you through setting up local debugging for Nitric applicati
1616

1717
Debugging serverless-style applications can be challenging due to the way functions are triggered by events. For Python, we can use [`debugpy`](https://github.com/microsoft/debugpy) to connect a debugger to the service while it runs.
1818

19-
### 1. Modify the Python entry point
19+
### 1. Add debugpy to our project
20+
21+
```bash
22+
uv add debugpy
23+
```
24+
25+
### 2. Modify the Python entry point
2026

2127
Add the following lines to the top of the service file (e.g., `services/api.py`). This starts a debug server that the IDE can attach to.
2228

@@ -27,14 +33,18 @@ host, port = debugpy.listen(("0.0.0.0", 52509)) # Static port for consistent de
2733
print(f"✅ Debugpy is listening on {host}:{port}", flush=True)
2834
```
2935

30-
> A **static port** (`52509`) is used so the IDE knows which port to connect to. Update the `launch.json` configuration to match this port before starting the debugger.
36+
<Note>
37+
A **static port** (`52509`) is used so the IDE knows which port to connect to.
38+
Update the `launch.json` configuration to match this port before starting the
39+
debugger.
40+
</Note>
3141

32-
### 2. Update `nitric.yaml`
42+
### 3. Update `nitric.yaml`
3343

34-
Modify the `start` command to include an auto-reloader and ensure Python does not use frozen modules, which can interfere with `debugpy`, E.g.
44+
Modify the `start` command to include an auto-reloader and ensure Python does not use frozen modules, which can interfere with `debugpy`:
3545

3646
```yaml
37-
name: message-board
47+
name: my-project
3848
services:
3949
- basedir: ''
4050
match: services/*.py
@@ -49,9 +59,12 @@ runtimes:
4959
args: {}
5060
```
5161
52-
> This configuration restarts the service on file changes and includes the necessary flags for debugging compatibility.
62+
<Note>
63+
This configuration restarts the service on file changes and includes the
64+
necessary flags for debugging compatibility.
65+
</Note>
5366
54-
### 3. Configure `launch.json` in VS Code
67+
### 4. Configure `launch.json` in VS Code
5568

5669
VS Code uses a `launch.json` file to define how it should start or attach to a debugging session. In this case, the debugger doesn't launch the application itself—it attaches to the running service that was started manually from the terminal.
5770

@@ -85,14 +98,17 @@ To create or update the launch.json file:
8598
}
8699
```
87100

88-
> Ensure the `port` matches the value used in the `debugpy.listen()` call. If the port changes in the code, update it here as well.
101+
<Note>
102+
Ensure the `port` matches the value used in the `debugpy.listen()` call. If
103+
the port changes in the code, update it here as well.
104+
</Note>
89105

90-
### 4. Running the debugger
106+
### 5. Running the debugger
91107

92-
Start your nitric service with `nitric start` and start the debugger.
108+
Start your nitric service with `nitric start`, in the Terminal, both the Nitric runtime output and the debugpy listener output will be visible, including the active debug port.
93109

94-
![vscode](/docs/images/guides/python-debugging/debugger.png)
110+
![vscode](/docs/images/guides/python-debugging/terminal.png)
95111

96-
In the Terminal, both the Nitric runtime output and the debugpy listener output will be visible, including the active debug port.
112+
Now run the debugger and add breakpoints or watch variables.
97113

98-
In this example, a breakpoint has been hit on line 16 of `message_api.py`, within an HTTP handler for the `/messages` endpoint.
114+
![vscode](/docs/images/guides/python-debugging/debug.png)
216 KB
Loading
264 KB
Loading
-600 KB
Binary file not shown.
76.2 KB
Loading

0 commit comments

Comments
 (0)