Python Debugging Tips: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Python Debugging Tips=
[[Category:LanguageBindings::PySide]]
 
= Python Debugging Tips =


This Wiki page lists some useful tips for analyzing unexpected behaviors in Python programs.
This Wiki page lists some useful tips for analyzing unexpected behaviors in Python programs.


==Using Python trace module==
== Using Python trace module ==
 
If your program is crashing and no information is being shown about what happened (as usually is the case with a segfault), then the Python module '''trace''' can be useful to point which line of the program is causing the crash or at least the line where the program stopped. Just add “-m trace —trace” parameters to the Python executable and every line being executed will be printed on the screen. Supposing your program is called ‘script.py’, one way to use '''trace''' is shown below:


Keep in mind that this will make your program run slower, as the standard output will show everything being executed at the time. For more information about the '''trace''' module, you can consult its official documentation [http://docs.python.org/library/trace.html here.] ''[docs.python.org]''
If your program is crashing and no information is being shown about what happened (as usually is the case with a segfault), then the Python module '''trace''' can be useful to point which line of the program is causing the crash or at least the line where the program stopped. Just add "-m trace —trace" parameters to the Python executable and every line being executed will be printed on the screen. Supposing your program is called 'script.py', one way to use '''trace''' is shown below:


===Categories:===
<code><br />$ python -m trace —trace script.py<br /></code>


* [[:Category:LanguageBindings|LanguageBindings]]
Keep in mind that this will make your program run slower, as the standard output will show everything being executed at the time. For more information about the '''trace''' module, you can consult its official documentation &quot;here.&quot;:http://docs.python.org/library/trace.html
** [[:Category:LanguageBindings::PySide|PySide]]

Revision as of 11:32, 24 February 2015


Python Debugging Tips

This Wiki page lists some useful tips for analyzing unexpected behaviors in Python programs.

Using Python trace module

If your program is crashing and no information is being shown about what happened (as usually is the case with a segfault), then the Python module trace can be useful to point which line of the program is causing the crash or at least the line where the program stopped. Just add "-m trace —trace&quot; parameters to the Python executable and every line being executed will be printed on the screen. Supposing your program is called 'script.py', one way to use trace is shown below:

<br />$ python -m trace trace script.py<br />

Keep in mind that this will make your program run slower, as the standard output will show everything being executed at the time. For more information about the trace module, you can consult its official documentation "here.":http://docs.python.org/library/trace.html