Komodo can be used to debug Python programs locally or remotely, including debugging in CGI environments. The instructions below describe how to configure Komodo and Python for debugging. For general information about using the Komodo debugger, see Komodo Debugger Functions.
Debugger commands can be accessed from the Debug menu, by shortcut keys, or from the Debug Toolbar. For a summary of debugger commands, see the Debugger Command List.
To specify which Python interpreter Komodo should use to debug and run Python programs locally:
On the Debug menu or Debug Toolbar, click Go/Continue or Step In to invoke the debugging session. See Komodo Debugger Functions for full instructions on using Komodo's debugging functionality.
When debugging a Python program remotely, the program is executed on the remote machine, and the debug output is sent to Komodo. Komodo controls the debugging session once the session starts on the remote machine.
To debug a Python program remotely, the Python debugger client package must be installed on the remote machine. Packages are available for download from the Komodo Remote Debugging page. Alternatively, if your remote machine uses the same platform as the machine on which you installed Komodo, you can get the Python debugger client files from the pythonlib and bin subdirectories of the Komodo installation directory for your platform. The locations are as follows:
Mac OS X
For Python3 remote debugging, use the package named python3lib.
To install the Python Remote Debugger:
To verify that the setup is correct, run the following command:
If this command prints the word "ok", you can move to the next step. If this command results in an
python -c "import dbgp.client; print 'ok'"
ImportErrorthen you need to resolve the error before continuing. 3. Put the bin\pydbgp.py script (bin/pydbgp on Linux and Mac OS X) somewhere convenient. This is the main script that you run to start a remote debugging session.
Tip: Placing the pydbgp.py script in a directory that is on your PATH environment variable, makes the script easier to run. On Windows, also make sure that your PATHEXT environment variable includes .py. On Linux and Mac OS X, ensure that the pydbgp script is executable by running this command:
chmod u+x **path/to**/pydbgp
Now try running this command:
If the setup is correct, the internal help documentation for running pydbgp is displayed.
Note: The debugging client relies on certain core python library files (e.g.
types). If you have added custom modules to your python site-packages,
sys.path with the same name as those imported by
pydbgp, the debugger may not work properly.
Python remote debugging sessions are started in one of three ways:
dbgp.client.brk()directly from within your Python program code.
All methods require that the Python remote debugger client package is installed on the remote machine (see Installing the Python Remote Debugger).
|**Note**: For Komodo to open an editable copy of the file, a [Mapped URI](debugger#remote_uri_mapping) must be created to link the file on the remote filesystem with the URI Komodo receives from the remote debugger.|
To start a Python remote debugging session from the command line:
python -S **path/to/**pydbgp.py -d **host:port** **your-script.py**
where host:port identifies the port on which Komodo is listening. By default, Komodo listens for remote debugger connections on port 9000. For example, if the "remote" machine is the same machine on which Komodo is running, start a debugging session with this command:
python -S **path/to/**pydbgp.py -d localhost:9000 **your-script.py**
Other options for using the pydbgp.py driver are available by running:
python -S **path/to/**pydbgp.py --help
If you are connecting to a DBGP Proxy, you must specify an
ide_key value with the
-k option to pydbgp.py. Listener port and DBGP Proxy settings are configurable via Edit|Preferences|Debugger. Select Debug|Listener Status to view the current settings.
|**Note:** If your application requires that _sitecustomize.py_ is loaded, you must run Python with the -S argument. The debugger will load site.py at the appropriate time. Komodo is unable to debug _sitecustomize.py_ due to how Python handles loading of that file.|
**Note:** If you followed the tip described in [Installing the Python Remote Debugger](#Installing_the_Python_Remote_Debugger) the basic command is:
To break into a remote debugging session directly from within your Python code:
brk()function in the
dbgp.clientmodule to set a hard breakpoint. For example, the following simple Python script will break into a debugging session when execution reaches the
from dbgp.client import brk def foo(): print "Hello, World!" brk(host="**mybox**", port=**9000**) print "Goodbye."
brk() function supports the following arguments:
"Just-in-time debugging" allows the remote debugger to connect to Komodo if an uncaught exception occurs during execution (i.e. if a Python exception reaches the top level of your Python program). By adding the following lines of code to the beginning of your script, you can trap and explore the execution state of your Python program when an exception reaches the top level:
from dbgp.client import brkOnExcept brkOnExcept(host='**mybox**', port=**9000**)
If and when an exception reaches the top level of your Python program, a post-mortem debugging session is started in Komodo at the line at which the exception is raised. The debug session is automatically placed in interactive mode so that you can inspect the current program environment, exactly like a Python interactive shell.
brkOnExcept() function takes the same arguments as
brk(). As with
brkOnExcept() attempts to connect to
localhost on port 9000 with an
idekey of USER or USERNAME if no arguments are specified.
To debug CGI applications written in Python:
dbgp.clientFunctions in Python Programs to call the Python remote debugger from within the application. Start the remote application through a web browser instead of running it from the command line.
© 2017 ActiveState Software Inc. All rights reserved. ActiveState®,
Komodo®, ActivePerl®, ActivePython®, and ActiveTcl® are registered
trademarks of ActiveState.
All other marks are property of their respective owners.