poll with timeout

This commit is contained in:
Gregor Kleen 2023-05-29 16:20:23 +02:00
parent 47eb6ee63b
commit b8076256cb

View File

@ -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<ts>[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()