user1601716
user1601716

Reputation: 1993

flask + gunicorn, make a redirect stick to the same worker thread

having an issue where I have a flask application being run by gunicorn with multiple workers because a single request can take 30 min +... I have multiple workers so I can have multiple of these long requests at the same time.

I am having an issue where I have a post, and I am setting variables in the post, then I redirect to a different page to run the 30 minute request.

the issue is i notice that when the redirect is serviced by a different worker, it has no memory of the variables i set in the other worker.

the solution that comes to mind is keep the redirect in the same worker, but i'm not sure if this can be done.

Any suggestions on how to get around this?

Thanks!

Upvotes: 0

Views: 906

Answers (1)

gilsho
gilsho

Reputation: 921

When you redirect the user to a different page you can pass in the relevant parameters in the GET request. something like this:

@app.route('/first', methods=['POST'])
def first():
    var = request.form['variable']
    return redirect(url_for('second', variable=var))


@app.route('/second', methods=['GET'])
def second():
    var = request.args['variable']

Upvotes: 1

Related Questions