Debugging Python Wallaroo Applications
As you're developing Python Wallaroo applications, there will come a time where you will need to do some debugging during your development process. Debugging can be as simple as inserting a
The simplest way to do some debugging would be to include a
Reverse classes. Here's an example in our
compute function in our
def compute(self, data): print "compute", data return data[::-1]
In this example, we'll be printing the incoming data before we reverse it.
>>> u = u'\ua000abcd\u07b4' >>> print u Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\ua000' in position 0: ordinal not in range(128)
With a streaming input application, you can't always be certain about the contents of the data you try to print. However, you can effectively avoid this sort of error by printing the byte representation of your data instead, using
print repr(data). In that case, the same code that resulted in an error before will provide a useful printout of the contents of the data object:
u'\ua000abcd\u07b4' print repr(u) u'\ua000abcd\u07b4'u =
Debugging Using PDB
If you need a more robust tool to do debugging, the Python standard library provides
pdb is an interactive debugger which gives you the option to set breakpoints, inspect the stack frames, and other features expected from an interactive debugger. A quick example of using
pdb in your application would be importing the
pdb module and then calling its
set_trace() function. The
import pdb command goes in the module you pass to
--application-module when running
machida. Usage example:
import pdb # ... def application_setup(arg): pdb.set_trace() # ...
The above will insert a breakpoint in the current stack frame and allow you to inspect the
pdb comes with a nice set of features so if you're interested in using it go have a look at the official documentation.
Other Debugging Options
pdb is great because they're available on all platforms. However, we realize you might have your own debugging process. We encourage you to use the tools that best fit your needs and we are available to help get you set up if needed.