0

I have one flask application 'merge.py'. From this I am calling two request and getting their response as:

from flask import Flask
from flask import request, jsonify
import json
import time
import requests

app = Flask(__name__)

@app.route('/check')
def check_working():
    result_1 = requests.get('http://0.0.0.0:8080/hello').content
    result_2 = requests.get('http://0.0.0.0:7000/bye').content
    return "True"

if __name__=='__main__':
    app.run(debug=True,host='128.7.7.10',threaded=True)

Right now when I am running the above file, both the request '/hello' and '/bye' running synchronously. How I can make them asynchronous with uwsgi. Suppose '/hello' is taking 10sec and '/bye' is taking 5sec, so total time it should take to execute is 10sec not 15sec. I want to collect the output of both the request. How I can achieve the asynchronous behavior here.

Thanks

neha
  • 1,858
  • 5
  • 21
  • 35
  • Possible duplicate of [Making an asynchronous task in Flask](https://stackoverflow.com/questions/31866796/making-an-asynchronous-task-in-flask) – Chandra Pavan Dec 28 '17 at 10:22
  • 1
    This isn't specific to flask, as what you are asking about is generally writing async code in python. have a look at this question : https://stackoverflow.com/questions/11968689/python-multithreading-wait-till-all-threads-finished – Daniel Dror Dec 28 '17 at 11:03

0 Answers0