python - Gunicorn 内存配额超出
问题描述
我有一个需要在浏览器中显示视频流的 python 应用程序。为了显示流,我向另一个路由(/video_feed)发出请求。这是代码:
@app.route("/video_feed")
def video_feed():
# return the response generated along with the specific media
# type (mime type)
return Response(generate(),
mimetype="multipart/x-mixed-replace; boundary=frame")
def generate():
# grab global references to the output frame and lock variables
global outputFrame, lock
# loop over frames from the output stream
while True:
# wait until the lock is acquired
with lock:
# check if the output frame is available, otherwise skip
# the iteration of the loop
if outputFrame is None:
continue
# encode the frame in JPEG format
(flag, encodedImage) = cv2.imencode(".jpg", outputFrame)
# ensure the frame was successfully encoded
if not flag:
continue
# yield the output frame in the byte format
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
bytearray(encodedImage) + b'\r\n')
<html>
<head>
<title>Pi Video Surveillance</title>
</head>
<body>
<h1>Pi Video Surveillance</h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
@app.route('/stream')
def show_video_stream():
return render_template("stream.html")
def prepare_video_stream():
print("It might be streaing")
global outputFrame, lock
coordinates_file = "data/parking_spot_coordinates.yml"
with open(coordinates_file, "r") as coordinates_data:
coordinates = yaml.load(coordinates_data)
stream_url = os.environ.get('RTSP_URL')
video_stream = VideoStream(coordinates)
# video_stream.stream_video()
video_capture = cv2.VideoCapture(stream_url)
fps = video_capture.get(cv2.CAP_PROP_FPS)
print(fps)
video_capture.set(cv2.CAP_PROP_BUFFERSIZE, 0)
while video_capture.isOpened():
frame = video_stream.get_frame(video_capture)
# acquire the lock, set the output frame, and release the
# lock
with lock:
outputFrame = frame.copy()
@app.before_first_request
def start_stream_processing_thread():
# # start a thread that will perform motion detection
t = threading.Thread(target=prepare_video_stream)
t.daemon = True
t.start()
使用内置的烧瓶服务器在本地运行时一切运行良好,但我尝试将应用程序部署到 heroku,并使用 gunicorn 作为服务器。这是Procfile:
web: gunicorn app:app
检查heroku日志时,我得到以下信息:错误R14(超出内存配额)
我怎样才能避免这种情况?
解决方案
推荐阅读
- c# - 使用 Ajax 过滤模型更新 foreach 循环中的表(asp.net mvc c#)
- java - Jsoup 在该行显示所有 text()
- components - 在哪里可以找到 Blazor 默认包含的组件列表?
- javascript - 未捕获的 TypeError:x.replace 不是函数。在此更改之前没有得到
- pandas - 根据条件 pandas 过滤数据框
- css - React 组件的样式不适用于 Heroku
- google-cloud-platform - 有没有办法在 Google Natural Language API 情感分析中明确设置句子的开头和结尾?
- python - 将 EPSG:3857(“web 墨卡托”)中散景中瓷砖提供者的投影更改为我在 EPSG:4326 中的来源
- python - Python 请求库中的分块编码消息
- javascript - 如何从 HTML 中的选择标签中提取选定的值?