From a9872dff8a961e054dc89f869f4f33f2bc44d15e Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Fri, 1 Feb 2019 14:05:34 -0700 Subject: [PATCH] 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. --- docs/examples/download_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/download_file.py b/docs/examples/download_file.py index 4a11074c..65da8434 100644 --- a/docs/examples/download_file.py +++ b/docs/examples/download_file.py @@ -5,7 +5,7 @@ def download_file(reactor, url, destination_filename): destination = open(destination_filename, 'wb') - d = treq.get(url) + d = treq.get(url, unbuffered=True) d.addCallback(treq.collect, destination.write) d.addBoth(lambda _: destination.close()) return d