Debugar

traceback

Mostrar tota la traça a on estem:

import traceback
traceback.print_stack()

PDB

Incloure en el codi on volem debugar:

    import pdb; pdb.set_trace()

Llavors des de consola podem debugar:

h(elp) [command]

w(here)

d(own)

u(p)

s(tep)

n(ext)

unt(il)

r(eturn)

c(ont(inue))

l(ist) [first[, last]]

a(rgs)

p expression

pp expression

[!]statement

q(uit)

http://docs.python.org/2/library/pdb.html

cProfile

https://bitbucket.org/snippets/zikzakmedia/dnbqy

1) python -m cProfile script.py

2) import cProfile; cProfile.runctx('funcio()', globals(), locals())

3) Afegir decorador @do_cprofile a la funció, definint previament:

import cProfile


def do_cprofile(func):
    def profiled_func(*args, **kwargs):
        profile = cProfile.Profile()
        try:
            profile.enable()
            result = func(*args, **kwargs)
            profile.disable()
            return result
        finally:
            profile.print_stats()
    return profiled_func


CategoryPython

Python/Debugar (last edited 2018-09-18 09:49:16 by resteve)

Contenidos creados por el equipo de Zikzakmedia. Creative Commons By-NC-SA

PythonZikzakmedia