better(?) polling
This commit is contained in:
parent
b8076256cb
commit
f455d9f4d6
@ -462,11 +462,27 @@ def main():
|
||||
stderr_logger = proc_logger.getChild("stderr")
|
||||
|
||||
poll = select.poll()
|
||||
poll.register(proc.stdin, select.POLLOUT | select.POLLHUP)
|
||||
poll.register(proc.stdout, select.POLLIN | select.POLLHUP)
|
||||
poll.register(proc.stderr, select.POLLIN | select.POLLHUP)
|
||||
poll.register(
|
||||
proc.stdin, select.POLLOUT | select.POLLHUP | select.POLLERR
|
||||
)
|
||||
poll.register(
|
||||
proc.stdout,
|
||||
select.POLLIN
|
||||
| select.POLLPRI
|
||||
| select.POLLHUP
|
||||
| select.POLLERR,
|
||||
)
|
||||
poll.register(
|
||||
proc.stderr,
|
||||
select.POLLIN
|
||||
| select.POLLPRI
|
||||
| select.POLLHUP
|
||||
| select.POLLERR,
|
||||
)
|
||||
pollc = 3
|
||||
events = poll.poll(500)
|
||||
logger.debug("First poll...")
|
||||
events = poll.poll()
|
||||
logger.debug("Done, %d events", len(events))
|
||||
while pollc > 0 and len(events) > 0:
|
||||
for rfd, event in events:
|
||||
if event & select.POLLOUT:
|
||||
@ -479,13 +495,20 @@ def main():
|
||||
logger.debug("Done")
|
||||
else:
|
||||
proc.stdin.close()
|
||||
if event & select.POLLIN:
|
||||
if event & select.POLLIN or event & select.POLLPRI:
|
||||
if rfd == proc.stdout.fileno():
|
||||
if line := proc.stdout.readline():
|
||||
stdout_logger.info(line[:-1])
|
||||
if rfd == proc.stderr.fileno():
|
||||
if line := proc.stderr.readline():
|
||||
stderr_logger.info(line[:-1])
|
||||
if event & select.POLLERR:
|
||||
if rfd == proc.stdin.fileno():
|
||||
logger.error("STDIN error")
|
||||
if rfd == proc.stdout.fileno():
|
||||
logger.error("STDOUT error")
|
||||
if rfd == proc.stderr.fileno():
|
||||
logger.error("STDERR error")
|
||||
if event & select.POLLHUP:
|
||||
if rfd == proc.stdin.fileno():
|
||||
logger.debug("STDIN closed")
|
||||
@ -497,12 +520,19 @@ def main():
|
||||
pollc -= 1
|
||||
|
||||
if pollc > 0:
|
||||
events = poll.poll(500)
|
||||
logger.debug("Poll...")
|
||||
events = poll.poll()
|
||||
logger.debug("Done, %d events", len(events))
|
||||
else:
|
||||
logger.debug("Nothing left to poll")
|
||||
events = []
|
||||
|
||||
for handler in proc_logger.handlers:
|
||||
handler.flush()
|
||||
|
||||
logger.debug("Waiting on subprocess...")
|
||||
ret = proc.wait()
|
||||
logger.debug("Done")
|
||||
if ret != 0:
|
||||
raise Exception(f"borg subprocess exited with returncode {ret}")
|
||||
finally:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user