Browse Source

backup: stop main thread if reader thread dies unexpectedly

_thread.interrupt_main will trigger KeyboardInterrupt in the main thread.
master
Jim Paris 2 years ago
parent
commit
3024cf2e69
1 changed files with 9 additions and 1 deletions
  1. +9
    -1
      backup.py

+ 9
- 1
backup.py 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()



Loading…
Cancel
Save