# debugpy - a debugger for Python
An implementation of the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/) for Python 3.
[](https://dev.azure.com/debugpy/debugpy/_build/latest?definitionId=1&branchName=main)
[](https://raw.githubusercontent.com/microsoft/debugpy/main/LICENSE)
[](https://pypi.org/project/debugpy/)
[](https://pypi.org/project/debugpy/)
#### Coverage
| OS | Coverage |
|---|---|
| Windows |  |
| Linux |  |
| Mac |  |
## `debugpy` CLI Usage
### Debugging a script file
To run a script file with debugging enabled, but without waiting for the client to attach (i.e. code starts executing immediately):
```console
-m debugpy --listen localhost:5678 myfile.py
```
To wait until the client attaches before running your code, use the `--wait-for-client` switch.
```console
-m debugpy --listen localhost:5678 --wait-for-client myfile.py
```
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:
```console
-m debugpy --listen 5678 ...
```
in which case the default interface is 127.0.0.1.
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:
```console
-m debugpy --listen 0.0.0.0:5678 myfile.py
```
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.
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.
### Debugging a module
To run a module, use the `-m` switch instead of filename:
```console
-m debugpy --listen localhost:5678 -m mymodule
```
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.
### Attaching to a running process by ID
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.
```console
-m debugpy --listen localhost:5678 --pid 12345
```
### Ignoring subprocesses
The following command will ignore subprocesses started by the debugged process.
```console
-m debugpy --listen localhost:5678 --pid 12345 --configure-subProcess False
```
## `debugpy` Import usage
### Enabling debugging
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.
```python
import debugpy
debugpy.listen(("localhost", 5678))
...
```
As with the `--listen` command line switch, hostname can be omitted, and defaults to `"127.0.0.1"`:
```python
debugpy.listen(5678)
...
```
### Waiting for the client to attach
Use the `debugpy.wait_for_client()` function to block program execution until the client is attached.
```python
import debugpy
debugpy.listen(5678)
debugpy.wait_for_client() # blocks execution until client is attached
...
```
### `breakpoint()` function
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.
```python
import debugpy
debugpy.listen(...)
while True:
...
breakpoint() # or debugpy.breakpoint()
...
```
## Debugger logging
To enable debugger internal logging via CLI, the `--log-to` switch can be used:
```console
-m debugpy --log-to path/to/logs ...
```
When using the API, the same can be done with `debugpy.log_to()`:
```py
debugpy.log_to('path/to/logs')
debugpy.listen(...)
```
In both cases, the environment variable `DEBUGPY_LOG_DIR` can also be set to the same effect.
When logging is enabled, debugpy will create several log files with names matching `debugpy*.log` in the specified directory, corresponding to different components of the debugger. When subprocess debugging is enabled, separate logs are created for every subprocess.
没有合适的资源?快使用搜索试试~ 我知道了~
debugpy-1.6.2.zip

共310个文件
py:236个
hpp:10个
txt:8个

0 下载量 98 浏览量
2024-05-29
23:16:14
上传
评论
收藏 4.24MB ZIP 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论





























收起资源包目录





































































































共 310 条
- 1
- 2
- 3
- 4
资源评论


程序员Chino的日记
- 粉丝: 4259
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 以东营为例分析广播电视网络技术应用与优化.docx
- 大二计算机网络期末测验考试附标准答案.doc
- 人工智能技术在计算机辅助翻译软件中的应用与评价.docx
- 矿山机电安装工程项目施工及项目管理探讨.docx
- 实验一应用系统开发过程及常用指令实-单片机.doc
- PLC的五层电梯控制系统设计方案[].doc
- 依托大模型与 RAG 技术构建的柑橘知识库及专家平台 融合大模型和 RAG 技术的柑橘领域知识库与专家平台 基于大模型 + RAG 技术打造的柑橘知识库与专家服务平台 借助大模型与 RAG 构建的柑橘
- 书生 Intern 大模型,为投资决策注入科技强劲动能
- 2019CCF-BDCI大赛 OCR赛题第一名 天晨破晓团队 文字识别模型baseline
- 非常好看的个人网页,带后台管理
- 自动适应个人官方网站引导页博客网页工作室引导HTML模版源码
- 2019CCF-BDCI 大赛 OCR 赛题冠军天晨破晓团队文字识别模型 baseline
- 在 Android 设备上完成大模型的部署工作
- 部署大模型到Android设备
- Flet分页自定义组件CustomPaginationComponent封装版
- 针对 AI 大模型的提示词攻击工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
