tornado 4.0 新加tornado.web.stream_request_body decorator ,用于stream request
Streaming uploads let you handle large requests without buffering everything into memory, but there is still generally some limits to what you"re willing to handle. The max_buffer_size and max_body_size parameters are now separate, but they both default to 100MB. With streaming uploads, you can increase max_body_size as much as you want without increasing your memory requirements, but make sure you have enough disk space (or s3 budget, etc) to handle the uploads you"ll get. You can even set max_body_size on a per-request basis by calling self.request.connection.set_max_body_size() from prepare()
import tornado.web import tornado.ioloop MB = 1024 * 1024 GB = 1024 * MB TB = 1024 * GB MAX_STREAMED_SIZE = 1*GB @tornado.web.stream_request_body class MainHandler(tornado.web.RequestHandler): def prepare(self): self.f = open("xxxxxxxx", "wb") # 如果不設(shè)max_body_size, 不能上傳>100MB的文件 self.request.connection.set_max_body_size(MAX_STREAMED_SIZE) def post(self): print("upload completed") self.f.close() def data_received(self, data): self.f.write(data) if __name__ == "__main__": application = tornado.web.Application([ (r"/", MainHandler), ]) application.listen(7777) tornado.ioloop.IOLoop.instance().start()
tornado.web.stream_request_body 源碼
測(cè)試:
curl -v -XPOST --data-binary @presto-server-0.144.2.tar.gz -127.0.0.1:7777/
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/45482.html
摘要:本文主要介紹了在框架中使用實(shí)現(xiàn)簡(jiǎn)單服務(wù)器的過(guò)程。在網(wǎng)絡(luò)通信中,需要發(fā)送二進(jìn)制流數(shù)據(jù)函數(shù)負(fù)責(zé)數(shù)據(jù)組包,即將數(shù)據(jù)按照規(guī)定的傳輸協(xié)議組合起來(lái)函數(shù)負(fù)責(zé)數(shù)據(jù)拆包,即按照規(guī)定的協(xié)議將數(shù)據(jù)拆分開(kāi)來(lái)。不多說(shuō),具體實(shí)現(xiàn)代碼咱們來(lái)看一下。 本文主要介紹了在tornado框架中,使用tcpserver,tcpclient,struct.pack(),struct.unpack實(shí)現(xiàn)簡(jiǎn)單echo服務(wù)器的過(guò)程。 ...
摘要:譯者說(shuō)于年月日發(fā)布,該版本正式支持的關(guān)鍵字,并且用舊版本編譯同樣可以使用這兩個(gè)關(guān)鍵字,這無(wú)疑是一種進(jìn)步。其次,這是最后一個(gè)支持和的版本了,在后續(xù)的版本了會(huì)移除對(duì)它們的兼容。 譯者說(shuō) Tornado 4.3于2015年11月6日發(fā)布,該版本正式支持Python3.5的async/await關(guān)鍵字,并且用舊版本CPython編譯Tornado同樣可以使用這兩個(gè)關(guān)鍵字,這無(wú)疑是一種進(jìn)步。其次...
閱讀 1151·2023-04-26 03:02
閱讀 1191·2023-04-25 19:18
閱讀 2595·2021-11-23 09:51
閱讀 2577·2021-11-11 16:55
閱讀 2631·2021-10-21 09:39
閱讀 1710·2021-10-09 09:59
閱讀 2005·2021-09-26 09:55
閱讀 3532·2021-09-26 09:55