From b8076256cb0fea943e3e5ce1a3b27c050067ae4e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 29 May 2023 16:20:23 +0200 Subject: [PATCH] poll with timeout --- k8s_gitlab_borg/__main__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/k8s_gitlab_borg/__main__.py b/k8s_gitlab_borg/__main__.py index 2604369..9c2a5bb 100644 --- a/k8s_gitlab_borg/__main__.py +++ b/k8s_gitlab_borg/__main__.py @@ -37,6 +37,7 @@ import json import subprocess +from select import PIPE_BUF import select import time import math @@ -65,8 +66,6 @@ TIME_PATTERNS = OrderedDict( BACKUP_PATTERN = re.compile(r"^(?P[0-9]+)_.*_gitlab_backup\.tar$") -BUFFER_SIZE = os.sysconf("SC_PAGESIZE") - @dataclass(eq=True, order=True, frozen=True) class GitlabBackup: @@ -429,9 +428,9 @@ def main(): logger.debug("Read chunk of %d bytes", len(chunk)) offset += len(chunk) retries = 10 - while pagesize_chunk := chunk[:BUFFER_SIZE]: + while pagesize_chunk := chunk[:PIPE_BUF]: yield pagesize_chunk - chunk = chunk[BUFFER_SIZE:] + chunk = chunk[PIPE_BUF:] else: break except IncompleteRead as e: @@ -467,7 +466,7 @@ def main(): poll.register(proc.stdout, select.POLLIN | select.POLLHUP) poll.register(proc.stderr, select.POLLIN | select.POLLHUP) pollc = 3 - events = poll.poll() + events = poll.poll(500) while pollc > 0 and len(events) > 0: for rfd, event in events: if event & select.POLLOUT: @@ -498,7 +497,7 @@ def main(): pollc -= 1 if pollc > 0: - events = poll.poll() + events = poll.poll(500) for handler in proc_logger.handlers: handler.flush()