While working with AppEngine locally (i.e. using dev_appserver.py), is there anyway to do a step-by-step debugging? It is a too old fashion to use logging.info() or similar functions to show the values of all the variables in the code and decide where the error is.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
PyCharm Professional Edition enables step-by-step debugging out of the box.
If you're willing to go through a few setup steps, the free version, PyCharm Community Edition, can be configured to work with Google App Engine python too. You won't get all the advantages of PyCharm Professional Edition such as deployment, but you'll be able to do step by step debugging and get code navigation and auto-completion working.
To enable debugging, edit the PyCharm Run/Debug configuration by setting:
--automatic_restart=no --max_module_instances="default:1" .
For more detailed instructions, explanations, and how get code completion working in aup PyCharm CE project, see http://www.enkisoftware.com/devlogpost-20141231-1-Python_Google_App_Engine_debugging_with_PyCharm_CE.html.
If you're working on Windows and you want to use PyTools (Microsoft Visual Studio Community) to debug python for GAE, see http://www.enkisoftware.com/devlogpost-20140814-1-Python_Google_App_Engine_debugging_with_PyTools.html
To expand a little bit on codeape's answer's first suggestion: Because dev_appserver.py mucks about with stdin, stdout, and stderr, a little more work is needed to set a "code breakpoint". This does the trick for me:
You'll have to run
dev_appserver.py
from the command line rather than via the GUI App Engine Launcher. When thepdb.set_trace()
line is executed, you will be dropped into thepdb
debugger at that point.Eclipse PyDev supports debugging and AppEngine.
http://code.google.com/appengine/articles/eclipse.html
If the local appengine process is a normal python process you have a couple of options:
In your code, place "code breakpoints":
import pdb; pdb.set_trace()
. Rundev_appserver.py
as normal, and the python debugger will break when it reaches the line with the code.Run
dev_appserver.py
in pdb. From the shell:$ python -m pdb dev_appserver.py
. To set a breakpoint, use the commandb filename.py:linenumber
. Then use thec
command to continue. See http://docs.python.org/library/pdb.html#debugger-commandsSee the pdb module documentation.