Improve cancelling Borg process (#786)

* Try SIGINT and then SIGTERM
* Minor: shlex.join needs Python >=3.8
This commit is contained in:
Manu 2021-02-11 14:24:24 +08:00 committed by GitHub
parent 38cd7cd2e6
commit 09e978220f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import logging
from collections import namedtuple
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, TimeoutExpired
from vorta.i18n import trans_late
from vorta.models import EventLogModel, BackupProfileMixin
@ -269,9 +269,17 @@ class BorgThread(QtCore.QThread, BackupProfileMixin):
mutex.unlock()
def cancel(self):
"""
First try to terminate the running Borg process with SIGINT (Ctrl-C),
if this fails, use SIGTERM.
"""
if self.isRunning():
mutex.unlock()
self.process.send_signal(signal.SIGINT)
try:
self.process.wait(timeout=3)
except TimeoutExpired:
self.process.terminate()
mutex.unlock()
self.terminate()
def process_result(self, result):

View File

@ -1,5 +1,4 @@
import plistlib
import shlex
import subprocess
import xml
from typing import Optional, Iterator
@ -71,7 +70,7 @@ def call_ipconfig_getpacket(bsd_device):
try:
return subprocess.check_output(cmd)
except subprocess.CalledProcessError:
logger.debug("Command %s failed", shlex.join(cmd))
logger.debug("Command %s failed", ' '.join(cmd))
return b''
@ -80,4 +79,4 @@ def call_networksetup_listallhardwareports():
try:
return subprocess.check_output(cmd)
except subprocess.CalledProcessError:
logger.debug("Command %s failed", shlex.join(cmd))
logger.debug("Command %s failed", ' '.join(cmd))