V
V
Vitaly2017-06-06 13:04:30
Multithreading
Vitaly, 2017-06-06 13:04:30

How in Flask on Pyhon 3 using _thread not to delay the http response while processing is in progress?

All the best! I’m studying python a little, but it’s a bit difficult with streams .... until I figured it out to the end :(
I have a simple http server on Flask , a POST request comes to it, python processes it, but for a long time, respectively, the client waits a long time for an answer, and cannot resend a new request until it receives this response, and the response itself is not important ...

Tried something like this:

def append_to_sheet(first, second):
  row = [datetime.now(), first, second]
  sheet.append_row(row)

@app.route("/action" , methods=['POST'])
def cardAction():
  first_param: request.args.get('first'),
  second_param: request.args.get('second')

  while True:
    _thread.start_new_thread(append_to_sheet, (first_param, second_param))
  
  return "ok!"


But it doesn't work :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-06-06
@immaculate

Heavy things should be taken out in separate processes by means of queue. For example, Celery, there are other easier and more difficult options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question