2015-10-31 31 views
0

我在我所裨CAM模块裨B2模型和我有蟒烧瓶应用我从 随后以下miguelgrinberg博客 http://blog.miguelgrinberg.com/post/video-streaming-with-flask裨烧瓶视频流停止错误:[错误32]破碎管

https://github.com/miguelgrinberg/flask-video-streaming

,我已经加入GEVENT作为Web服务器,以满足多线程摄像头流连接和 修改脚本如下

#!/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) 

每次我启动服务器,并尝试访问它使用客户端我得到这个错误信息

随着该服务器停止流mjpeg大约30分钟或更多时间后开始。我还评论出部分,其中有客户端后

In Camera_pi.py file

# if there hasn't been any clients asking for frames in** 
      # the last 10 seconds stop the thread 
      #if time.time() - cls.last_access > 10000: 
      # break 

错误信息为下一个10秒没有连接 连接到服务器即使仍然出现此消息,我可以观看流,但不超过30分钟或更经过30分钟+框架的浏览器冻结,并刷新也没有工作,我不得不CTRL + C蟒蛇app.py并再次启动:

(streampi)[email protected] ~/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': <open file '<stderr>', mode 'w' at 0x76d850d0>, 
'wsgi.input': <gevent.pywsgi.Input object at 0x763cb5d0>, 
'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 

回答

0

破裂的管道错误指示瓶试图写一个套接字从另一端关闭,这是一边 客户端。

如果您正在进行流式处理并突然关闭浏览器窗口,则会出现此错误。在这种情况下,错误是无害的,它只会导致服务该客户端的线程停止,这是客户端消失时所需的线程。

对于任何类型的连接中断,您都会收到此错误。为了使流媒体更加健壮,您需要安装一个系统来检查客户端连接是否存在,如果不存在,可能需要重新加载映像,以便重新建立流。

要检查客户端是否保持连接状态,可以记录客户端获取最后一个视频帧时的时间戳。然后,由客户端发送的Ajax调用可以检查帧被检索到多久以前,如果这个长度超过某个阈值,则声明连接中断并触发客户端刷新图像。