Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion failed: Flask server stops after script is run

Tags:

python

flask

I have a flask application that when the user clicks a button on the index page, they trigger a report to be generated and it is downloaded to their browser using the send_file() funtion.

Every time a report is created and downloaded the server stops and I get the below error in the terminal. It needs to be restarted every time and I can't figure out how to fix it. Any ideas? :)

flask_app.py file:

from flask import Flask, render_template, request, url_for, flash
import create_report
from flask_debugtoolbar import DebugToolbarExtension
from flask import send_file

app = Flask(__name__)
filename = ""

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/handle_data", methods=['GET', 'POST'])
def handle_data():
    text = request.form['accountinput']
    preprocessed_text = text.lower()
    filename = create_report.start_script(preprocessed_text)
    path = "reports/" + filename
    return send_file(path, as_attachment=True)

if __name__ == '__main__':
    app.run(debug=True)

Error in terminal:

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.60.100/AppKit.subproj/NSView.m, line 14485.
like image 260
beth Avatar asked Jun 19 '26 17:06

beth


1 Answers

You should start your program with

import matplotlib
matplotlib.use('Agg')

since create_report module use matplotlib, and for matplotlib this is a common case.

like image 53
mingaleg Avatar answered Jun 21 '26 08:06

mingaleg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!