title: Django return http early flush (chunked response)
body: <p>I have an algorithm which waits for almost 5 seconds to generate response and I want to send an ack (http 200) to user as soon as he sends request to tell him that his request has been received and wait for 5 seconds.</p>
  
  <p>Generator function:</p>
  
  <pre><code>def chunked_res():
      yield "Chunk 1"
  
      stop = time.time() + 5    # wait for 5 seconds
      while time.time() &lt; stop:
          pass
  
      yield "Chunk 2"
  </code></pre>
  
  <p>And in some view:</p>
  
  <pre><code>response = HttpResponse ( chunked_res() )
  response['Connection'] = 'close'
  response['Transfer-Encoding'] = 'chunked'
  response['status'] = 200
  return response
  </code></pre>
  
  <p><strong>Response in browser:</strong></p>
  
  <p>"Transfer-Encoding: chunked\nstatus: 200\nConnection: close\nContent-Type: text/html; charset=utf-8\n\nChunk 1Chunk 2"</p>
  
  <p><strong>Problem:</strong>
  I am getting required response(Chunk 1, Chunk 2) but after 5 seconds. I want to send "Chunk 1" first and then "Chunk 2" after 5 seconds(update respose). Are there any particular settings/changes to implement this? </p>
  
  <p><strong>Update:</strong></p>
  
  <p>Django = 1.4
  python = 2.7</p>