backup: stop main thread if reader thread dies unexpectedly

_thread.interrupt_main will trigger KeyboardInterrupt in the main thread.
This commit is contained in:
Jim Paris 2021-10-17 20:00:55 -04:00
parent a540f4336f
commit 3024cf2e69

View File

@ -15,6 +15,7 @@ import select
import pathlib
import threading
import subprocess
import _thread # for interrupt_main
import typing
@ -359,7 +360,14 @@ def main(argv: typing.List[str]):
sys.stdout.flush()
captured_output.append(line)
fh.close()
reader = threading.Thread(target=reader_thread, args=(borg.stdout,))
def _reader_thread(fh):
try:
return reader_thread(fh)
except BrokenPipeError:
pass
except Exception:
_thread.interrupt_main()
reader = threading.Thread(target=_reader_thread, args=(borg.stdout,))
reader.daemon = True
reader.start()