title: Avoiding server timeout in long running POST request
body: <p>I'm sending POST request using python <a href="http://www.python-requests.org/" rel="nofollow">requests</a> library and reading data from an iterator.</p>
  
  <p>If the iterator yields data quickly all works perfectly.</p>
  
  <p>The problem is that my iterator sometimes "takes a break", the server disconnects due to inactivity and my client raises a <code>Broken pipe</code> exception at socket level. I can't avoid pauses on source iterator because they depends on  computation time.</p>
  
  <p>The server is SOLR, but I think this should be a more general question.</p>
  
  <p>To be more precise the situation is like this (I'm simplifying because original code is quite complex):</p>
  
  <pre><code>import requests
  def myObjectsIter():
      #this generator yields custom objects and sometimes pauses
  
  def myObjectsSerializerIter():
      yield "&lt;add&gt;"
      for o in myObjectsIter():
          #o.serialize returns an XML string for SOLR update (&lt;doc&gt;...&lt;/doc&gt;)
          yield o.serialize()
      yield "&lt;/add&gt;"
  
  requests.post("http://mysolr/mycore/update", data=myObjectsSerializerIter())
  
  #When myObjectsIter pauses for more than (i think) 60 seconds the last call raises [Errno 32] Broken pipe
  </code></pre>
  
  <p>Does anyone know any good practice to avoid such a situation?</p>