提供电影文件时 Django 出现 MemoryError

发布于 2024-10-13 22:22:35 字数 253 浏览 2 评论 0原文

在我的 Django 应用程序中,我列出了包含电影(大约 400 MB)的目录的内容。当我尝试在浏览器中播放电影时,出现 MemoryError。我在“媒体”文件夹中有此电影内容,我已将其标记为静态。

我相信这部电影应该直接通过我的网络服务器提供,而不需要将请求传递给 Django。我的配置中是否存在一些错误,或者是否有一个不同的解决方案可用于像我一样提供电影服务。

我将 lighttpd 与 Django 和 FCGI 一起使用。

谢谢。

In my Django application, I list the contents of a directory which contains movies (of around 400 MB). When I try to play the movie in the browser, I get MemoryError. I have this movie content inside the "media" folder which I have marked to serve as statically.

I believe this movie should have been served directly through my web server without passing the request to Django. Is there some error in my configuration or is there whole together a different solution available for serving movies as in my case.

I am using lighttpd with Django and FCGI.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余厌 2024-10-20 22:22:35

可能是您尚未配置 lighttpd 来处理对 /media/ 本身的请求,并且 Django 正在调试模式下运行(您的 settings.txt 中的 DEBUG = True)。 py)。

如果您遵循 Django 自己的 lighttpd 部署文档,这不应该发生。

Could it be that you haven't configured lighttpd to handle requests to /media/ itself and Django is running in debug mode (DEBUG = True in your settings.py).

If you follow Django's own docs for lighttpd deployment, this shouldn't happen.

街角卖回忆 2024-10-20 22:22:35

您的内存不足,因为您读取了内存中的整个文件&上菜前先缓冲一下。从 django urls.py 中删除静态 url 配置,并将该 url 配置为由 lighthttpd 提供服务。

但对于这种规模的电影来说,最好的服务方式是流媒体。查看任何媒体流服务器,看看它是否对您有帮助。这可能对你有帮助。
通过 flowplayer 和 lighthttpd 流式传输电影

--Sai

You are running out of memory because you read the whole file in memory & buffer it before serving it. Remove the static url config from django urls.py and configure that url to be served by lighthttpd.

But the best way for movies of that size are best served is streaming. Take a look at any media streaming server and see if it helps you. This may help you.
Streaming movies by flowplayer and lighthttpd

--Sai

浅笑轻吟梦一曲 2024-10-20 22:22:35

我自己解决了这个错误。

实际上问题是我的lighttpd 服务器配置错误。问题是我已将网络服务器配置为将每个请求重定向到 Django,并允许 Django 处理请求并通过网络服务器提供响应。

因此,当我请求播放一个大电影文件(比如大约 400 MB)时,该请求发送到 Django,并且 Django 不知何故将该文件加载到内存中。

由于它是一个内存有限的嵌入式设备,Django抛出了一个“MemoryError”。

我更改了网络服务器的配置,一切都顺利进行。

希望这对将来的人有帮助。干杯!

I solved the error myself.

Actually the problem was with a misconfiguration with my lighttpd server. The problem was that I had configured my webserver to redirect every request to Django and allow Django to process the request and server the response through the webserver.

So, what was happening is when I request to play a large movie file (say around 400 MB), this request went to Django and somehow Django was loading the file in the memory.

Since it was an embedded device with a limited memory, Django threw an "MemoryError".

I changed the configuration of my webserver and everything worked like a charm.

Hope this helps someone in the future. Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文