rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

NameError: name 'profile' is not defined #111

Closed muyueyue closed 5 years ago

muyueyue commented 6 years ago

Hi,I add @profile on a function in Flask project. When I started the Flask project, always occur error as follows: NameError: name 'profile' is not defined How should I solve it?

PeterPanUnderhill commented 6 years ago

Same problem here...

gregsadetsky commented 6 years ago

Solution for Flask: pass use_reloader=False to app.run hence:

app.run(use_reloader=False)

Cheers 😄

gregsadetsky commented 6 years ago

Small additional comment -- I'm not sure if this is something Flask-, or my-project-specific (probably the former), but for line_profiler to work properly, your view function definitions should be in the following form:

@app.route("/")
@profile
def index():

i.e., the @profile decorator should be "within" the @app.route one, not the other way around.

muyueyue commented 6 years ago

@gregsadetsky Thank you for your reply. The reason for my error is run Flask in the debug mode, as follows: app.run(host='0.0.0.0', port=5000, debug=True) When I remove 'debug=True' the error disappeared.

caethan commented 5 years ago

Not line-profiler related.