Debugging Tips

 

http://bit.ly/pdbtips

 

Roy Hyunjin Han

@crosscompute

 

PyCon Asia Pacific 2016

Seoul, South Korea

Debugging scenarios

  1. Prototype
  2. Development
  3. Production

Prototype debugging

Examine exception while running interpreter

 

 

Pinpoint variables in scope

 

 

Step through execution at breakpoint

Prototype debugging

Examine exception while running interpreter

    jupyter notebook
        debug

 

Pinpoint variables in scope

 

 

Step through execution at breakpoint

Examine exception while running interpreter

Prototype debugging

Examine exception while running interpreter

    jupyter notebook
        debug

 

Pinpoint variables in scope

    import IPython; IPython.embed()

        whos

 

Step through execution at breakpoint

Use

whos

for

scope

 

Prototype debugging

Examine exception while running interpreter

    jupyter notebook
        debug

 

Pinpoint variables in scope

    import IPython; IPython.embed()

 

Step through execution at breakpoint

    import pudb; pudb.set_trace()

Step through execution

Development debugging

Drop into debugger without modifying code

 

 

Trace on CTRL-C

 


Debug threads or Docker containers

Development debugging

Drop into debugger without modifying code

    pudb -- xyz.py arg1 arg2

 

Trace on CTRL-C

 


Debug threads or Docker containers

Debug without modifying code

pudb -- xyz.py arg1 arg2

Development debugging

Drop into debugger without modifying code

    pudb -- xyz.py arg1 arg2

 

Trace on CTRL-C

    import pudb; pudb.set_interrupt_handler()


Debug threads or Docker containers

Trace on CTRL-C

Development debugging

Drop into debugger without modifying code

    pudb -- xyz.py arg1 arg2

 

Trace on CTRL-C

    import pudb; pudb.set_interrupt_handler()


Debug threads or Docker containers

    import wdb; wdb.set_trace()

Use wdb to debug threads

Use wdb for Docker containers

Production debugging

Use namespaced logger with rsyslog server

 


Debug tests

Production debugging

Use namespaced logger with rsyslog server

    logging.getLogger(__name__)

 

Debug tests

Use namespaced logger

Production debugging

Use namespaced logger with rsyslog server

    logging.getLogger(__name__)


Debug tests

    pip install pdbpp; py.test --pdb

Debug tests

pip install pdbpp; py.test --pdb

Examine exception from interpreter jupyter notebook
    debug
Pinpoint variables in scope import IPython; IPython.embed()
    whos
Set breakpoint import pudb; pudb.set_trace()
Run with debugger pudb -- xyz.py arg1 arg2
Start debugger on CTRL-C import pudb
pudb.set_interrupt_handler()
Trace threads import wdb; wdb.set_trace()
Record logs logging.getLogger(__name__)
Debug tests pip install pdbpp; py.test --pdb

Debugging Tips

By Roy Hyunjin Han

Debugging Tips

  • 3,418