def read_by_deadline(resp, sock, deadline, n):
"""
Read up to N bytes from a socket. If there's nothing to read, signal that
it's closed.
"""
time_left = deadline - get_time()
# Avoid past-deadline special cases by setting a small timeout instead.
sock.settimeout(max(time_left, 0.001))
try:
data = resp.raw.read(n)
except (ReadTimeoutError, socket.timeout) as e:
raise TimeoutError('Timeout waiting for container logs.')
if len(data) == 0:
raise SocketClosed()
return data
评论列表
文章目录