Add a time.sleep(0) to the tight loop in gzipstream to make sure we never use 100% of a machine CPU

This commit is contained in:
Joseph Schorr 2014-12-01 16:19:13 -05:00
parent 5cb36fe053
commit 1e993b04ef

View file

@ -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