Skip to content

Commit a9872df

Browse files
committed
examples: stream downloaded file without buffering
Prior to this change, treq would buffer the entire file in memory, and Python's memory usage would rise to match the entire file size.
1 parent 2d45c82 commit a9872df

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/examples/download_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def download_file(reactor, url, destination_filename):
77
destination = open(destination_filename, 'wb')
8-
d = treq.get(url)
8+
d = treq.get(url, unbuffered=True)
99
d.addCallback(treq.collect, destination.write)
1010
d.addBoth(lambda _: destination.close())
1111
return d

0 commit comments

Comments
 (0)