You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The hostname passed to `--listen` specifies the interface on which the debug adapter will be listening for connections from DAP clients. It can be omitted, with only the port number specified:
35
+
29
36
```console
30
37
-m debugpy --listen 5678 ...
31
38
```
39
+
32
40
in which case the default interface is 127.0.0.1.
33
41
34
42
To be able to attach from another machine, make sure that the adapter is listening on a public interface - using `0.0.0.0` will make it listen on all available interfaces:
43
+
35
44
```console
36
45
-m debugpy --listen 0.0.0.0:5678 myfile.py
37
46
```
47
+
38
48
This should only be done on secure networks, since anyone who can connect to the specified port can then execute arbitrary code within the debugged process.
39
49
40
50
To pass arguments to the script, just specify them after the filename. This works the same as with Python itself - everything up to the filename is processed by debugpy, but everything after that becomes `sys.argv` of the running process.
41
51
42
52
### Debugging a module
53
+
43
54
To run a module, use the `-m` switch instead of filename:
55
+
44
56
```console
45
57
-m debugpy --listen localhost:5678 -m mymodule
46
58
```
59
+
47
60
Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other debugpy switches work identically in this mode; in particular, `--wait-for-client` can be used to block execution until the client attaches.
48
61
49
62
### Attaching to a running process by ID
63
+
50
64
The following command injects the debugger into a process with a given PID that is running Python code. Once the command returns, a debugpy server is running within the process, as if that process was launched via `-m debugpy` itself.
65
+
51
66
```console
52
67
-m debugpy --listen localhost:5678 --pid 12345
53
68
```
54
69
55
70
### Ignoring subprocesses
71
+
56
72
The following command will ignore subprocesses started by the debugged process.
At the beginning of your script, import debugpy, and call `debugpy.listen()` to start the debug adapter, passing a `(host, port)` tuple as the first argument.
83
+
65
84
```python
66
85
import debugpy
67
86
debugpy.listen(("localhost", 5678))
68
87
...
69
88
```
89
+
70
90
As with the `--listen` command line switch, hostname can be omitted, and defaults to `"127.0.0.1"`:
91
+
71
92
```python
72
93
debugpy.listen(5678)
73
94
...
74
95
```
75
96
76
97
### Waiting for the client to attach
98
+
77
99
Use the `debugpy.wait_for_client()` function to block program execution until the client is attached.
100
+
78
101
```python
79
102
import debugpy
80
103
debugpy.listen(5678)
@@ -83,7 +106,9 @@ debugpy.wait_for_client() # blocks execution until client is attached
83
106
```
84
107
85
108
### `breakpoint()` function
109
+
86
110
Where available, debugpy supports the standard `breakpoint()` function for programmatic breakpoints. Use `debugpy.breakpoint()` function to get the same behavior when `breakpoint()` handler installed by debugpy is overridden by another handler. If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no client attached, the functions do nothing, and the code continues to execute normally.
111
+
87
112
```python
88
113
import debugpy
89
114
debugpy.listen(...)
@@ -97,11 +122,13 @@ while True:
97
122
## Debugger logging
98
123
99
124
To enable debugger internal logging via CLI, the `--log-to` switch can be used:
125
+
100
126
```console
101
127
-m debugpy --log-to path/to/logs ...
102
128
```
103
129
104
130
When using the API, the same can be done with `debugpy.log_to()`:
0 commit comments