title: Pi Flask Video streaming stops error: [Errno 32] Broken pipe
body: <p>I have Pi B2 model in which i have Pi Cam module and i have python flask app which i have followed from 
  following miguelgrinberg blog 
  <a href="http://blog.miguelgrinberg.com/post/video-streaming-with-flask" rel="nofollow">http://blog.miguelgrinberg.com/post/video-streaming-with-flask</a></p>
  
  <p><a href="https://github.com/miguelgrinberg/flask-video-streaming" rel="nofollow">https://github.com/miguelgrinberg/flask-video-streaming</a></p>
  
  <p>and i have added gevent as web server to serve multi thread camera streaming connection and
  modified script is as following</p>
  
  <pre><code>#!/usr/bin/env python
  from flask import Flask, render_template, Response
  from gevent import monkey; monkey.patch_all()
  
  
  # Raspberry Pi camera module (requires picamera package)
  from camera_pi import Camera
  
  app = Flask(__name__)
  
  
  @app.route('/')
  def index():
      """Video streaming home page."""
      return render_template('index.html')
  
  
  def gen(camera):
      """Video streaming generator function."""
      while True:
          frame = camera.get_frame()
          yield (b'--frame\r\n'
                 b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  
  
  @app.route('/video_feed')
  def video_feed():
      """Video streaming route. Put this in the src attribute of an img tag."""
      return Response(gen(Camera()),
                      mimetype='multipart/x-mixed-replace; boundary=frame')
  
  
  if __name__ == '__main__':
      monkey.patch_all()
      from gevent.wsgi import WSGIServer
      WSGIServer(('', 5000),app).serve_forever()
      #app.run(host='0.0.0.0', debug=True, threaded=True)
  </code></pre>
  
  <p>Every time i start server and try to access it using the client i got this error message </p>
  
  <p>Along with that server stop streaming mjpeg after some 30 min or more time after it start. I also commented out section where there is no connection 
  for next 10 sec </p>
  
  <blockquote>
    <p>In Camera_pi.py file</p>
  </blockquote>
  
  <pre><code># if there hasn't been any clients asking for frames in**
              # the last 10 seconds stop the thread
              #if time.time() - cls.last_access &gt; 10000:
              #    break
  </code></pre>
  
  <p>Error Message after client connect to server even if this message appears still i can view streaming but not more than 30 min or more after 30 + min frame in browser freezes and refresh also does not work i have to ctrl+c python app.py and start it again:</p>
  
  <pre><code>(streampi)pi@niravpi ~/svsapp/streampi $ python app.py
  Traceback (most recent call last):
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 508, in handle_one_response
      self.run_application()
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 495, in run_application
      self.process_result()
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 486, in process_result
      self.write(data)
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 376, in write
      self._write(data)
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 369, in _write
      self._sendall(data)
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 355, in _sendall
      self.socket.sendall(data)
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/socket.py", line 460, in sendall
      data_sent += self.send(_get_memory(data, data_sent), flags)
    File "/home/pi/svsapp/streampi/local/lib/python2.7/site-packages/gevent/socket.py", line 445, in send
      return sock.send(data, flags)
  error: [Errno 32] Broken pipe
  {'GATEWAY_INTERFACE': 'CGI/1.1',
   'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
   'HTTP_ACCEPT_ENCODING': 'gzip, deflate, sdch',
   'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,hi;q=0.6',
   'HTTP_CONNECTION': 'keep-alive',
   'HTTP_HOST': '192.168.1.6:5000',
   'HTTP_UPGRADE_INSECURE_REQUESTS': '1',
   'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
   'PATH_INFO': '/video_feed',
   'QUERY_STRING': '',
   'REMOTE_ADDR': '192.168.1.4',
   'REMOTE_PORT': '55311',
   'REQUEST_METHOD': 'GET',
   'SCRIPT_NAME': '',
   'SERVER_NAME': 'niravpi',
   'SERVER_PORT': '5000',
   'SERVER_PROTOCOL': 'HTTP/1.1',
   'SERVER_SOFTWARE': 'gevent/1.0 Python/2.7',
   'werkzeug.request': None,
   'wsgi.errors': &lt;open file '&lt;stderr&gt;', mode 'w' at 0x76d850d0&gt;,
   'wsgi.input': &lt;gevent.pywsgi.Input object at 0x763cb5d0&gt;,
   'wsgi.multiprocess': False,
   'wsgi.multithread': False,
   'wsgi.run_once': False,
   'wsgi.url_scheme': 'http',
   'wsgi.version': (1, 0)} failed with error
  
  192.168.1.4 - - [2015-10-31 14:44:53] "GET /video_feed HTTP/1.1" socket 479452 5.199595
  </code></pre>