Popular recipes tagged "debug" but not "dummy"http://code.activestate.com/recipes/tags/debug-dummy/2013-02-02T12:09:23-08:00ActiveState Code RecipesGet full caller name (package.module.function) (Python) 2012-11-30T21:54:46-08:00anatoly techtonikhttp://code.activestate.com/recipes/users/4168147/http://code.activestate.com/recipes/578352-get-full-caller-name-packagemodulefunction/ <p style="color: grey"> Python recipe 578352 by <a href="/recipes/users/4168147/">anatoly techtonik</a> (<a href="/recipes/tags/caller/">caller</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/logging/">logging</a>). </p> <p>This function allows to get fully qualified name of the calling function. I expected this field to be available from logging module, but it is not here <a href="http://docs.python.org/2/library/logging.html#logrecord-attributes" rel="nofollow">http://docs.python.org/2/library/logging.html#logrecord-attributes</a> It might be that it is too expensive for performance or just doesn't play well in some situations. I don't know. I use it solely when debugging and it is convenient.</p> <p>Also here: <a href="https://gist.github.com/2151727" rel="nofollow">https://gist.github.com/2151727</a></p> Attempt to estimate a size of Python object (Python) 2013-02-02T12:09:23-08:00Andrewhttp://code.activestate.com/recipes/users/4185117/http://code.activestate.com/recipes/578447-attempt-to-estimate-a-size-of-python-object/ <p style="color: grey"> Python recipe 578447 by <a href="/recipes/users/4185117/">Andrew</a> (<a href="/recipes/tags/debug/">debug</a>). Revision 6. </p> <p>This function is built on assumption, that no custom types was implemented. Function traversing the tree of given object and summing sizes of pointers and basic-types objects got with sys.getsizeof() function. For example, for this two dicts {'key': 'shortstring'} and {'key': 'veryverylongandconsumingstring'} my function will return different sizes, while sys.getsizeof() will return same. TODO - make that calculation of size covers pointers of circular references which for now is just passed by</p> Recipe With No Name Yet (Python) 2012-08-22T17:57:12-07:00Cyrilhttp://code.activestate.com/recipes/users/4182937/http://code.activestate.com/recipes/578221-recipe-with-no-name-yet/ <p style="color: grey"> Python recipe 578221 by <a href="/recipes/users/4182937/">Cyril</a> (<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/wrapper/">wrapper</a>). Revision 9. </p> <p>Not a very new recipe, but a short one and (I hope) useful :</p> <ul> <li>wrapping any function "f" with two decorators "enter_event" and "exit_event" that will trigger calling of user functions when, ... hum ... evidently, <strong>just before entering and just after exiting the "f" function</strong>.</li> </ul> <p>Typical usages :</p> <ul> <li>debugging on a function by function basis : <ul> <li>emit a trace in log file to see when functions are called and check sequences correctness (very usefull when programming by events)</li> <li>feed a profile analyzer (by fine tuning which functions are enabled)</li> <li>feed a code coverage analyzer ( " )</li> </ul></li> <li>kind of validator on function calling : <ul> <li>implement programming by contracts : <ul> <li>check that parameters values of "f" function will not have an unexpected value or be of an unexpected type</li> <li>this allow to increase code robustness by narrowing </li> </ul></li> <li>implement invariants (eg. check that returned value is always in the excepted range, ...)</li> <li>insure that a function follow specifications by meta-checking that has always predictable results (eg. return the fixed expected value for each possible input value, ...)</li> </ul></li> <li>minimum modification of existing code</li> <li><strong>in the same thinking line as the "monkey patching" concept</strong></li> </ul> <p>Notes on usage :</p> <ul> <li>recipe works on functions and any kind of methods (methods, class methods, and static methods)</li> <li>the usage order of "@enter_event" and "@exit_event" decorators doesn't matter : the result will be the same</li> </ul> <ul> <li><em>PLEASE VOTE FOR THIS RECIPE if you like it !</em></li> </ul> Komodo JS Macro: Execute JavaScript (JavaScript) 2012-05-07T13:21:30-07:00Patrick Clokehttp://code.activestate.com/recipes/users/4180275/http://code.activestate.com/recipes/578120-komodo-js-macro-execute-javascript/ <p style="color: grey"> JavaScript recipe 578120 by <a href="/recipes/users/4180275/">Patrick Cloke</a> (<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>). </p> <p>Executes a JavaScript file (or the selected text) and display the results in the command output window.</p> Conditionnal Breakpoint (Python) 2011-09-20T18:49:23-07:00s_h_a_i_ohttp://code.activestate.com/recipes/users/4177334/http://code.activestate.com/recipes/577874-conditionnal-breakpoint/ <p style="color: grey"> Python recipe 577874 by <a href="/recipes/users/4177334/">s_h_a_i_o</a> (<a href="/recipes/tags/breakpoint/">breakpoint</a>, <a href="/recipes/tags/debug/">debug</a>). Revision 2. </p> <p>Decorates a class so that it encounters a breakpoint for any call to class.method_name(self,<em>args,</em>*kwargs), where</p> <ul> <li>method_name is given by string</li> <li>only if arguments meet a test: arg_test(self,<em>args,</em>*kwargs) -> bool [default -> True]</li> </ul> <p>Behaviour easily changed for other actions than breakpoint (logging,...)</p> How to debug (deadlocked) multi threaded programs (Python) 2010-07-26T15:39:15-07:00Laszlo Nagyhttp://code.activestate.com/recipes/users/4150221/http://code.activestate.com/recipes/577334-how-to-debug-deadlocked-multi-threaded-programs/ <p style="color: grey"> Python recipe 577334 by <a href="/recipes/users/4150221/">Laszlo Nagy</a> (<a href="/recipes/tags/dead/">dead</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/stack/">stack</a>, <a href="/recipes/tags/thread/">thread</a>, <a href="/recipes/tags/trace/">trace</a>). </p> <p>Simple module that allows you to explore deadlocks in multi threaded programs.</p> Trace decorator for debugging (Python) 2011-01-24T18:40:51-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577551-trace-decorator-for-debugging/ <p style="color: grey"> Python recipe 577551 by <a href="/recipes/users/4173535/">Kevin L. Sitze</a> (<a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/inspection/">inspection</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/trace/">trace</a>). Revision 2. </p> <p>This package provides a decorator for tracing function and method calls in your applications. The tracing capabilities are managed through the logging package, and several mechanisms are provided for controlling the destination of the trace output.</p> <p>It also provides functionality for adding decorators to existing classes or modules.</p> Easy Exception, Error Handling and Debugging with Auto Logging (Python) 2010-04-06T20:40:05-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577144-easy-exception-error-handling-and-debugging-with-a/ <p style="color: grey"> Python recipe 577144 by <a href="/recipes/users/4173476/">AJ. Mayorga</a> (<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/error_propagation/">error_propagation</a>, <a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/logging/">logging</a>). Revision 5. </p> <p>Being new to Python and trying to chase where in my project exceptions were taking place always seems to take up a large amount of time. So I created this class that I now pretty use in all my projects to help me save time tracking exceptions and errors. its also has the ability to generate error logs or to output SQL query and data tuples for Database logging. Ive added sample code to give you an idea of how I normally use it. Hope this helps its saved me hours in tracking error/exception. Feed back would be great, mind you havent been Python all that long</p> Debugging a running python process by interrupting and providing an interactive prompt (Python) 2008-09-25T11:23:29-07:00Brian McErleanhttp://code.activestate.com/recipes/users/111980/http://code.activestate.com/recipes/576515-debugging-a-running-python-process-by-interrupting/ <p style="color: grey"> Python recipe 576515 by <a href="/recipes/users/111980/">Brian McErlean</a> (<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/interactive/">interactive</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/signal/">signal</a>). Revision 2. </p> <p>This provides code to allow any python program which uses it to be interrupted at the current point, and communicated with via a normal python interactive console. This allows the locals, globals and associated program state to be investigated, as well as calling arbitrary functions and classes.</p> <p>To use, a process should import the module, and call listen() at any point during startup. To interrupt this process, the script can be run directly, giving the process Id of the process to debug as the parameter.</p> Sensible Loop Status (Python) 2008-10-05T02:14:52-07:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576528-sensible-loop-status/ <p style="color: grey"> Python recipe 576528 by <a href="/recipes/users/4167420/">David Lambert</a> (<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/status/">status</a>). </p> <p>A LoopStatus object tests true according to geometric progression or time intervals. This enables rapid time estimates for long running codes, typically in a loop, without producing copious highly repetitive output.</p>