Skip to content

Instantly share code, notes, and snippets.

@agalera
Created May 3, 2016 07:34
Show Gist options
  • Save agalera/4e10d19f221dc5eea8d69dcec6e34075 to your computer and use it in GitHub Desktop.
Save agalera/4e10d19f221dc5eea8d69dcec6e34075 to your computer and use it in GitHub Desktop.
tornado upload
from tornado.httpserver import HTTPServer
import tornado.ioloop
import tornado.web
import uuid
from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor
@tornado.web.stream_request_body
class MainHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(max_workers=400)
@run_on_executor
def post(self):
print "ok"
def data_received(self, data):
print "chunk size: %s " % len(data)
@run_on_executor
def get(self):
print "get"
import time; time.sleep(4)
print "end"
self.write('ok')
self.finish()
MB = 1024 * 1024
GB = 1024 * MB
TB = 1024 * GB
if __name__ == "__main__":
application = tornado.web.Application([
(r"/upload", MainHandler),
])
http_server = HTTPServer(application, max_body_size=11*GB, max_buffer_size=11*GB)
http_server.bind(8888)
http_server.start(1)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment