Using breakpoint() in Python3

Use Python’s breakpoint() function to easily step through your code.

The breakpoint() function was added in Python 3.7 and is part of Python’s built-in functions.

Using breakpoint() is as simple as adding it to your script and running the script.

Here is a simple example using flask.

from flask import Flask


app = Flask(__name__)

@app.route("/")
def index():
    breakpoint()
    return "Hello, breakpoint()!"

After starting the flask application, your terminal will be in a pdb instance and you can start debugging. Use the continue command to break out of the debugger and let the code continue executing. Use next to step to the next line of code.

References

Author: rfmeier

Product developer at WPEngine and runner from Schaumburg, Illinois. I work with php and Python; Spending most of my time digging into source code to see how it all works.