SimpleHTTPServer - 提供大文件

时间:2012-09-23 16:24:54

标签: python http simplehttpserver

我正在将python -m SimpleHTTPServer用于一个小项目。文件index.html引用了一些视频。     <video><source src="big_buck_bunny_480p_stereo.ogg"></video> 此文件的大小为159 MB。当我尝试下载它时,SimpleHTTPServer会抛出一些错误消息而不是我的视频。

Marc-Laptop - - [23/Sep/2012 18:18:29] "GET /big_buck_bunny_480p_stereo.ogg HTTP
/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.4.38', 51152)
Traceback (most recent call last):
  File "C:Program Files (x86)PythonlibSocketServer.py", line 284, in _handle
_request_noblock
    self.process_request(request, client_address)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 310, in process
_request
    self.finish_request(request, client_address)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 323, in finish_
request
    self.RequestHandlerClass(request, client_address, self)
  File "C:Program Files (x86)PythonlibSocketServer.py", line 640, in __init_
_
    self.finish()
  File "C:Program Files (x86)PythonlibSocketServer.py", line 693, in finish
    self.wfile.flush()
  File "C:Program Files (x86)Pythonlibsocket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen

----------------------------------------

1 个答案:

答案 0 :(得分:3)

simpleHTTPServer试图缓冲所有内容,实际上会因内存不足而爆炸。最好是异步执行,但simpleHTTPServer不知道如何做到这一点。检查thread。有人提出了simpleHTTPserver的修改版本:SimpleAsyncHTTPServer.py