# debugpy - a debugger for Python
[![Build Status](https://dev.azure.com/debugpy/debugpy/_apis/build/status/debugpy-test-automation?branchName=main)](https://dev.azure.com/debugpy/debugpy/_build/latest?definitionId=1&branchName=main)
[![GitHub](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/microsoft/debugpy/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/debugpy.svg)](https://pypi.org/project/debugpy/)
[![PyPI](https://img.shields.io/pypi/pyversions/debugpy.svg)](https://pypi.org/project/debugpy/)
#### Coverage
| OS | Coverage |
|---|---|
| Windows | ![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/debugpy/debugpy/2) |
| Linux | ![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/debugpy/debugpy/3) |
| Mac | ![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/debugpy/debugpy/4) |
This debugger implements the Debug Adapter Protocol: [debugProtocol.json](https://github.com/microsoft/vscode-debugadapter-node/blob/master/debugProtocol.json)
## `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 --config-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
In Python 3.7 and above, `debugpy` supports the standard `breakpoint()` function. Use `debugpy.breakpoint()` function for similar behavior and compatibility with older versions of Python. 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() on 3.6 and below
...
```
## 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.4.1.zip
共319个文件
py:248个
txt:8个
hpp:7个
0 下载量 165 浏览量
2024-05-30
14:46:18
上传
评论
收藏 3.99MB ZIP 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
debugpy-1.4.1.zip (319个子文件)
compile_windows.bat 2KB
pydevd_cython.c 1.95MB
pydevd_frame_evaluator.c 920KB
setup.cfg 283B
COPYING 1KB
attach.cpp 27KB
inject_dll.cpp 5KB
attach.cpp 4KB
run_code_on_dllmain.cpp 3KB
stdafx.cpp 1021B
attach_amd64.dll 43KB
attach_x86.dll 39KB
run_code_on_dllmain_amd64.dll 25KB
run_code_on_dllmain_x86.dll 22KB
attach_x86.dylib 23KB
attach_x86_64.dylib 20KB
inject_dll_amd64.exe 267KB
inject_dll_x86.exe 213KB
.gitignore 90B
.gitignore 86B
python.h 28KB
attach.h 2KB
stdafx.h 1KB
targetver.h 1KB
release_mem.h 84B
py_custom_pyeval_settrace.hpp 9KB
py_settrace.hpp 7KB
py_utils.hpp 4KB
run_code_in_memory.hpp 3KB
py_win_helpers.hpp 2KB
py_version.hpp 2KB
ref_utils.hpp 2KB
MANIFEST.in 123B
INSTALLER 5B
debugProtocol.json 145KB
debugProtocolCustom.json 11KB
LICENSE 1KB
README.md 5KB
README.md 1KB
DESCRIPTION.md 175B
METADATA 3KB
inject_dll_x86.pdb 4.89MB
inject_dll_amd64.pdb 4.75MB
attach_x86.pdb 804KB
attach_amd64.pdb 780KB
run_code_on_dllmain_amd64.pdb 588KB
run_code_on_dllmain_x86.pdb 580KB
PKG-INFO 1KB
PKG-INFO 1KB
pydevd_frame_evaluator.pxd 5KB
pydevd_cython.pxd 1KB
pydevd_schema.py 728KB
process.py 184KB
breakpoint.py 169KB
kernel32.py 166KB
peb_teb.py 159KB
pydevd.py 139KB
advapi32.py 121KB
interactive.py 86KB
thread.py 76KB
pydevd_comm.py 75KB
module.py 71KB
versioneer.py 69KB
event.py 67KB
crash.py 66KB
textio.py 63KB
pydevd_frame.py 59KB
messaging.py 59KB
debug.py 59KB
user32.py 58KB
pydevd_process_net_command_json.py 54KB
test_concrete.py 49KB
pydevd_api.py 48KB
_pydev_xmlrpclib.py 47KB
dbghelp.py 47KB
system.py 46KB
pydev_monkey.py 41KB
version.py 37KB
util.py 36KB
pydevd_file_utils.py 36KB
sql.py 35KB
pydevd_process_net_command.py 34KB
test_peephole_opt.py 33KB
pydev_runfiles.py 32KB
_pydev_inspect.py 32KB
pydevd_collect_bytecode_info.py 31KB
test_cfg.py 29KB
clients.py 27KB
pydevd_constants.py 27KB
scandir_vendored.py 26KB
pydevd_vars.py 26KB
shlwapi.py 26KB
pydevd_resolver.py 26KB
pydevd_bytecode_utils.py 26KB
context_amd64.py 25KB
disasm.py 25KB
window.py 24KB
pydev_console_utils.py 24KB
search.py 24KB
_pydev_SocketServer.py 24KB
共 319 条
- 1
- 2
- 3
- 4
资源评论
程序员Chino的日记
- 粉丝: 3670
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功