Comprehensive Python debugger backend for IDEs with remote debugging, breakpoints, variable inspection, and performance optimizations
—
Primary debugging functionality that provides the main interface for starting, stopping, and configuring debugging sessions. These functions handle debugger lifecycle, communication with IDE clients, and core debugging behavior configuration.
Core functions for starting and stopping debugging sessions with full control over connection parameters and debugging behavior.
def settrace(host=None, stdout_to_server=False, stderr_to_server=False, port=5678, suspend=True, trace_only_current_thread=False, overwrite_prev_trace=False, patch_multiprocessing=False, stop_at_frame=None, block_until_connected=True, wait_for_ready_to_run=True, dont_trace_start_patterns=(), dont_trace_end_patterns=(), access_token=None, client_access_token=None, notify_stdin=True, protocol=None, **kwargs):
"""
Start debugging session and connect to debugger server.
Parameters:
- host (str, optional): Debugger server hostname/IP (default: localhost)
- stdout_to_server (bool): Redirect stdout to debugger server
- stderr_to_server (bool): Redirect stderr to debugger server
- port (int): Debugger server port (default: 5678)
- suspend (bool): Suspend execution immediately after connecting
- trace_only_current_thread (bool): Only trace current thread
- overwrite_prev_trace (bool): Replace existing trace function (deprecated)
- patch_multiprocessing (bool): Enable debugging in child processes
- stop_at_frame: Frame to stop at (internal use)
- block_until_connected (bool): Block until debugger client connects
- wait_for_ready_to_run (bool): Wait for ready signal before continuing
- dont_trace_start_patterns (tuple): Filename patterns to skip tracing at start
- dont_trace_end_patterns (tuple): Filename patterns to skip tracing at end
- access_token (str, optional): Client access token for authentication
- client_access_token (str, optional): Server access token for authentication
- notify_stdin (bool): Notify about stdin redirections
- protocol (str, optional): Communication protocol to use
- **kwargs: Additional keyword arguments
Returns:
None
"""
def stoptrace():
"""
Stop active debugging session and disconnect from debugger server.
Returns:
None
"""Global debugger configuration functions for setting protocol, debug modes, and behavior options.
def config(protocol="", debug_mode="", preimport=""):
"""
Configure global debugger settings.
Parameters:
- protocol (str): Communication protocol ('', 'http', 'json')
- debug_mode (str): Debug mode settings
- preimport (str): Modules to preimport
Returns:
None
"""Debugger logging configuration for troubleshooting and development.
def log_to(log_file: str, log_level=3):
"""
Configure debugger logging output.
Parameters:
- log_file (str): Path to log file
- log_level (int): Logging level (0=None, 1=Critical, 2=Error, 3=Warning, 4=Info, 5=Debug)
Returns:
None
"""Functions for handling forked processes and multiprocessing scenarios.
def settrace_forked(setup_tracing=True):
"""
Setup debugger for forked child processes.
Parameters:
- setup_tracing (bool): Whether to setup tracing in child process
Returns:
None
"""Helper functions for debugging session management and troubleshooting.
def patch_stdin():
"""
Patch stdin for debugging input handling.
Returns:
None
"""
def enable_qt_support(qt_support_mode):
"""
Enable Qt application debugging support.
Parameters:
- qt_support_mode: Qt support mode configuration
Returns:
None
"""
def dump_threads(stream=None):
"""
Utility function to dump thread information for debugging.
Parameters:
- stream: Output stream (default: stdout)
Returns:
None
"""
def main():
"""
Command-line entry point for standalone debugging.
Returns:
None
"""Internal command dispatching for handling debugger protocol messages.
def dispatch():
"""
Dispatch debugger commands from IDE client.
Returns:
None
"""import pydevd
# Connect to IDE debugger on localhost
pydevd.settrace('localhost', port=5678)
# Your application code
def calculate_result():
x = 10
y = 20
return x + y
result = calculate_result()
print(f"Result: {result}")
# Stop debugging when done
pydevd.stoptrace()import pydevd
# Configure debugger protocol and logging
pydevd.config(protocol='http', debug_mode='True')
pydevd.log_to('/tmp/pydevd.log', log_level=4)
# Start debugging with multiprocessing support
pydevd.settrace(
host='192.168.1.100',
port=5678,
suspend=False, # Don't suspend immediately
trace_only_current_thread=False,
patch_multiprocessing=True, # Debug child processes
stdout_to_server=True,
stderr_to_server=True
)import os
import pydevd
# Start debugging in parent process
pydevd.settrace('localhost', port=5678)
pid = os.fork()
if pid == 0:
# Child process - setup debugging for fork
pydevd.settrace_forked()
# Child process code here
print("In child process")
else:
# Parent process continues with debugging
print("In parent process")
os.waitpid(pid, 0)import pydevd
from PyQt5.QtWidgets import QApplication, QMainWindow
# Enable Qt support before starting debugging
pydevd.enable_qt_support('auto')
pydevd.settrace('localhost', port=5678)
app = QApplication([])
window = QMainWindow()
window.show()
# Qt event loop will work properly with debugger
app.exec_()# Connection dispatch modes
DISPATCH_APPROACH_NEW_CONNECTION = 1
DISPATCH_APPROACH_EXISTING_CONNECTION = 2
# Package version
__version__: strInstall with Tessl CLI
npx tessl i tessl/pypi-pydevd