Reputation: 11
I'm new to tornado and I want build a simple website for watching movie. Of course,hello world website is successful and I want to add a movie in the empty website.Therefore I write a html using video label in html 5.
<html>
<body>
<video autoplay=true>
<source src="aa.mp4" type="video/mp4"></source>
</video>
</body>
</html>
The code in tornado is simple as well.
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')
A picture is OK, but when I use video which is 500MB. MemoryError arise.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1141, in _when_complete
callback()
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1167, in _execute_finish
self.finish()
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 760, in finish
self.flush(include_footers=True)
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 703, in flush
chunk = b"".join(self._write_buffer)
MemoryError
I feel like the problem is the browser download the whole video,So the function cannot return and throw a exception. Is it right? And how to fix it,thanks a lot.
Thank you for help and I write a line code to serve the video file. However I find it is still something wrong. It is OK when the file is a picture,and it goes wrong when I serve a video file which is much bigger.
(r"/(.*)",tornado.web.StaticFileHandler,{"path":"/home/alex/one/static"})
Upvotes: 1
Views: 240
Reputation: 6788
StaticFileHandler
should be able to handle large files.
From StaticFileHandler
docs:
This handler is intended primarily for use in development and light-duty file serving; for heavy traffic it will be more efficient to use a dedicated static file server (such as nginx or Apache). We support the HTTP Accept-Ranges mechanism to return partial content (because some browsers require this functionality to be present to seek in HTML5 audio or video).
If you use an older version of Tornado, you should update to the newest version.
Or as the docs say, use a dedicated static file server (such as nginx or Apache).
Upvotes: 1
Reputation: 22134
Which version of Tornado are you using? The stack trace looks old. StaticFileHandler
gained the ability to serve large files without loading them all into memory at once in version 4.0.
Upvotes: 0