An implementation of the Debug Adapter Protocol for Python
Перейти к файлу
Adam Yoblick abf4bb651a
Merge pull request #1722 from microsoft/build_pydevd_binaries
Build pydevd binaries before running tests
2024-11-05 14:25:29 -06:00
.github Remove pydevd workflow since we build these as part of CI now 2024-10-31 16:55:06 -05:00
.vscode Delete blank line 2023-07-21 11:50:37 -07:00
azure-pipelines Fix bad paths 2024-11-05 13:33:38 -06:00
coverage Add code coverage for tests (excluding ptvsd.server and pydevd). 2019-09-18 21:42:51 -07:00
doc Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
src/debugpy In 3.12 findlinestarts seems to return None for line more often (#1721) 2024-11-04 11:19:37 -08:00
tests Try to get more logging from 3.13 failures (#1711) 2024-10-24 11:08:42 -07:00
.CodeQL.yml Fix excluded (library) path in CodeQL.yml. 2022-12-12 15:24:21 -08:00
.coveragerc Re-enable coverage for debugpy.common.log and use comments to exclude specific lines instead. 2023-09-05 13:20:31 -07:00
.env Enable discovery of ptvsd tests in VSCode. 2019-02-25 16:35:46 -08:00
.flake8 Dummy commit to test internal pipeline trigger 2023-08-18 14:37:16 -05:00
.gitattributes Corrected versioneer install 2022-03-10 10:47:35 -08:00
.gitignore Pull in pydevd sys.monitoring support (#1680) 2024-09-23 11:22:54 -07:00
.sonarcloud.properties Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
CODE_OF_CONDUCT.md Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
CONTRIBUTING.md Update instructions for pushing changes to PyDev.Debugger (#1715) 2024-10-30 15:51:36 -07:00
DESCRIPTION.md Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
LICENSE Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
MANIFEST.in Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
README.md Update README.md 2023-06-27 16:15:11 -07:00
SECURITY.md Rename ptvsd -> debugpy. 2020-01-17 11:57:13 -08:00
TROUBLESHOOTING.md Rename master -> main. 2020-10-21 09:33:31 -07:00
cgmanifest.json Add `$schema` to `cgmanifest.json` 2022-09-12 10:19:01 -07:00
clean.cmd Build attach_linux_*.so for manylinux1 using the official containers from PyPA. 2021-08-20 12:27:28 -07:00
debugpy.code-workspace Use Black formatter only for Python files. 2023-09-05 13:20:31 -07:00
pyproject.toml Updates from pydevd (#1706) 2024-10-21 10:17:39 -07:00
pytest.ini Updates from pydevd (#1706) 2024-10-21 10:17:39 -07:00
setup.cfg Fix #1008: Re-attaching continuously creates 'accept_worker' threads in debugpy 2022-08-15 14:32:56 -07:00
setup.py add debugpy entry point 2024-07-25 15:59:49 -05:00
sonar-project.properties Exclude server directory from sonar 2020-02-05 11:04:33 -08:00
subrepo.py Use `subrepo` to link to PyDev.Debugger instead of copying it (#1714) 2024-10-29 13:32:30 -07:00
tox.ini Get Python 3.13 to work (#1692) 2024-10-10 09:03:34 -07:00
versioneer.py Update versioneer to 0.23. 2022-08-18 12:53:01 -07:00

README.md

debugpy - a debugger for Python

An implementation of the Debug Adapter Protocol for Python 3.

Build Status GitHub PyPI PyPI

Coverage

OS Coverage
Windows Azure DevOps coverage
Linux Azure DevOps coverage
Mac Azure DevOps coverage

debugpy CLI Usage

For full details, see the Command Line Reference.

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):

-m debugpy --listen localhost:5678 myfile.py

To wait until the client attaches before running your code, use the --wait-for-client switch.

-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:

-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:

-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:

-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.

-m debugpy --listen localhost:5678 --pid 12345

Ignoring subprocesses

The following command will ignore subprocesses started by the debugged process.

-m debugpy --listen localhost:5678 --pid 12345 --configure-subProcess False

debugpy Import usage

For full details, see the API reference.

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.

import debugpy
debugpy.listen(("localhost", 5678))
...

As with the --listen command line switch, hostname can be omitted, and defaults to "127.0.0.1":

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.

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.

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:

-m debugpy --log-to path/to/logs ...

When using the API, the same can be done with debugpy.log_to():

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.