From 1e993b04efe8afe45f443e3a4044b6b80a9d02ca Mon Sep 17 00:00:00 2001
From: Joseph Schorr <joseph.schorr@coreos.com>
Date: Mon, 1 Dec 2014 16:19:13 -0500
Subject: [PATCH] Add a time.sleep(0) to the tight loop in gzipstream to make
 sure we never use 100% of a machine CPU

---
 util/gzipstream.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/util/gzipstream.py b/util/gzipstream.py
index e4f39c6da..0f9ce1e6b 100644
--- a/util/gzipstream.py
+++ b/util/gzipstream.py
@@ -3,6 +3,7 @@ Defines utility methods for working with gzip streams.
 """
 
 import zlib
+import time
 
 # Window size for decompressing GZIP streams.
 # This results in ZLIB automatically detecting the GZIP headers.
@@ -35,4 +36,8 @@ def calculate_size_handler():
       size_info.uncompressed_size += len(decompressor.decompress(current_data, CHUNK_SIZE))
       current_data = decompressor.unconsumed_tail
 
+      # Make sure we allow the scheduler to do other work if we get stuck in this tight loop.
+      if len(current_data) > 0:
+        time.sleep(0)
+
   return size_info, fn