rower2000
rower2000

Reputation: 53

Async handler deleted by wrong thread with easygui and flask

I have the following issue with a flask/Python program. The code snippet is as follows:

import flask as fk
import math
import easygui as gui

    
@app.route('/')
def index():
    return fk.render_template('template.html')


@app.route('/results', methods=['POST', 'GET'])
def result_calc():

    if fk.request.form['price_gas'] != '':
        try:
            if not math.isnan(float(fk.request.form['price_gas'])):
                gas_price = float(fk.request.form['price_gas'])
            else:
                raise ValueError
        except ValueError:
            gas_price = float(gui.enterbox("Please enter a valid input!", "Error..."))
    else:
        gas_price = 0

    return fk.render_template('results.html', price_tag=gas_price)

If the input in the "price_gas" input field in the corresponding HTML form is a valid number, it behaves as I want it to. The same is true if the field is empty.

However, if I do not have a string that can be converted to float, e.g. "0..15" instead of "0.15", it only works on the first run of the program. I get then the input prompt and can insert a new string, e.g. "0.15". Then the rest of the program runs fine and the program's result is displayed on the page "results.html". Once I navigate back from the results page to the HTML input form on the input website and re-run the program, I get

Tcl_AsyncDelete: async handler deleted by the wrong thread

It seems to me that once the input field is called, it creates something running in the background that on the second turn blocks the proper execution of the code.

Thanks in advance for any idea how to fix this!

Upvotes: 4

Views: 156

Answers (0)

Related Questions