title: How to send asynchronous request using flask to an endpoint with small timeout session?
body: <p>I am new to backend development using <a href="http://flask.pocoo.org/" rel="noreferrer">Flask</a> and I am getting stuck on a confusing problem.  I am trying to send data to an endpoint whose Timeout session is 3000 ms. My code for the server is as follows.</p>
  
  <pre><code>from flask import Flask, request
  from gitStat import getGitStat
  
  import requests
  
  app = Flask(__name__)
  
  
  @app.route('/', methods=['POST', 'GET'])
  def handle_data():
      params = request.args["text"].split(" ")
  
      user_repo_path = "https://api.github.com/users/{}/repos".format(params[0])
      first_response = requests.get(
          user_repo_path, auth=(
              'Your Github Username', 'Your Github Password'))
  
      repo_commits_path = "https://api.github.com/repos/{}/{}/commits".format(params[
                                                                              0], params[1])
      second_response = requests.get(
          repo_commits_path, auth=(
              'Your Github Username', 'Your Github Password'))
  
      if(first_response.status_code == 200 and params[2] &lt; params[3] and second_response.status_code == 200):
  
          values = getGitStat(params[0], params[1], params[2], params[3])
  
          response_url = request.args["response_url"]
  
          payload = {
              "response_type": "in_channel",
              "text": "Github Repo Commits Status",
              "attachments": [
                  {
                      "text": values
                  }
                      ]
              }
  
          headers = {'Content-Type': 'application/json',
                  'User-Agent': 'Mozilla /5.0 (Compatible MSIE 9.0;Windows NT 6.1;WOW64; Trident/5.0)'}
  
          response = requests.post(response_url, json = test, headers = headers)
  
      else:
  
          return "Please enter correct details. Check if the username or reponame exists, and/or Starting date &lt; End date. \
                  Also, date format should be MM-DD"
  </code></pre>
  
  <p>My server code takes arguments from the request it receives and from that request's JSON object, it extracts parameters for the code. This code executes <em>getGitStats</em> function and sends the JSON payload as defined in the server code to the endpoint it received the request from.</p>
  
  <p>My problem is that I need to send a text confirmation to the endpoint that I have received the request and data will be coming soon. The problem here is that the function, <em>getGitStats</em> take more than a minute to fetch and parse data from Github API.</p>
  
  <p>I searched the internet and found that I need to make this call asynchronous and I can do that using queues. I tried to understand the application using <strong>RQ</strong> and <strong>RabbitMQ</strong> but I neither understood nor I was able to convert my code to an asynchronous format. Can somebody give me pointers or any idea on how can I achieve this?</p>
  
  <p>Thank you.</p>
  
  <p>------------Update------------</p>
  
  <p>Threading was able to solve this problem. Create another thread and call the function in that thread. </p>