python 3.x - Asyncio + Aiohttp socket.send() raised exception -
i have simple file server using aiohttp:
import os.path os import listdir import asyncio aiohttp import web import aiohttp_jinja2 import jinja2 @aiohttp_jinja2.template('template2.html') @asyncio.coroutine def get(request): root = os.path.abspath(os.path.dirname(__file__)) files = [file_name file_name in listdir(os.path.join(root,'files')) if os.path.isfile(os.path.join(root, 'files', file_name))] return {'files': files} if __name__ == "__main__": app = web.application() aiohttp_jinja2.setup(app, loader=jinja2.filesystemloader('/root/async')) app.router.add_route('get', '/', get) app.router.add_static('/files/' , '/root/async/files') loop = asyncio.get_event_loop() f = loop.create_server(app.make_handler(), '0.0.0.0', 8080) srv = loop.run_until_complete(f) print(' serving on ', srv.sockets[0].getsockname()) try: loop.run_forever() except keyboardinterrupt: pass
when test using siege tool with, example, such command:
siege -c 1000 -b -t 60 http://127.0.0.1:8080/files/kilobytes15.test
it raises lot of exceptions this:
socket.send() raised exception
and amount of data transferred small. assume socket closes before file sent user. appreciated suggestion. thank in advance! upd:
template2.html
<!doctype html> <html> <head><title>aiohttp test server</title></head> </body> <h3>list of files:</h3> <ul> {% item in files %} <li><a href="/files/{{ item }}">{{ item }}</a></li> {% endfor %} </ul> </body> </html>
/root/async directory contains template2.html , server script file(code mentioned @ start). /root/async/files directory contains dummy files of 15b, 15kb , 15mb sizes.
upd: exception not risen small files.
Comments
Post a Comment