Limitate speed of a socket-based data transferring

billie gnewsg at
Thu Sep 14 13:54:48 CEST 2006

Hi all. I'm writing a TCP-based application that I will use to trasfer
binary files through the network. This piece of code represents how do
I get a file from a remote peer and save it on my local hard drive:

file_obj = open('downloaded.ext', 'wb')
while 1:
    buf = sock.recv(2048)
    if len(buf) == 0:

I would like to know how could be possible to limit the file transfer
speed (for example: don't write more than 50 Kb/sec).
Some ideas?

Best regards

More information about the Python-list mailing list