Tornado download speed limits and traffic records #692

Closed
toadzhou opened this Issue Mar 10, 2013 · 4 comments

Comments

Projects
None yet
2 participants

WEBDISK need to purchase a speed limits and traffic features. Don't know how to implement tornado! ?
def get(self):
self.set_header("Content-Type", "application/zip")
self.set_header("Content-Disposition", "haha.zip")
self.write("XXXXXXX")

QOS & Real-time network traffic

Sorry!Please forgive me do not understand English!

Owner

bdarnell commented Mar 10, 2013

There's nothing built in for this, but you can do your own rate limiting with RequestHandler.flush and IOLoop.add_timeout. Write a chunk, flush it, and wait a bit before writing the next one.

bdarnell closed this Mar 10, 2013

Thank you for taking time to help me to answer,I also very like to use a tornado,But also want to ask you two questions.

1、Often appear the following warning how should solve?
WARNING:root:Read error on 7: [Errno 104] Connection reset by peer
WARNING:root:error on read

2、The following a logical question, but don't know how to change him. OK for the first time, second time stuck in it.

@tornado.web.asynchronous
def get(self):
    filename = "dist.rar"
    self.set_header("Cache-control", "private")
    self.set_header("Content-Type", "application/zip")
    self.set_header("Content-Disposition", "attachment;filename="+filename )
    self.set_header("Content-Length", getsize(filename))
    down_rate = 20
    try:
        with open(filename) as openfile:
            while True:
                data = openfile.read(down_rate * 1024)
                if not data:
                    self.finish()
                    openfile.close()
                    break
                self.write(data)
                self.flush()
                time.sleep(1)
    except Exception,ex:
        print str(ex)

Hope to help have a look at the thank you

Owner

bdarnell commented Mar 11, 2013

This is not a bug report; for questions and support you should use the mailing list instead: http://groups.google.com/group/python-tornado

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment