Avoid deadlock when calling subprocess.Popen(), ignore terminated borg processes when finding mount points. Fixes #187

This commit is contained in:
Manu 2019-02-16 12:05:37 +08:00 committed by Manuel Riel
parent 304ac3b90e
commit b23cdf9851
2 changed files with 18 additions and 17 deletions

View File

@ -143,7 +143,7 @@ class BorgThread(QtCore.QThread, BackupProfileMixin):
logger.info('Running command %s', ' '.join(self.cmd))
p = Popen(self.cmd, stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True,
env=self.env, cwd=self.cwd, preexec_fn=os.setsid)
env=self.env, cwd=self.cwd, start_new_session=True)
self.process = p
# Prevent blocking of stdout/err. Via https://stackoverflow.com/a/7730201/3983708

View File

@ -243,22 +243,23 @@ def get_mount_points(repo_url):
for proc in psutil.process_iter():
try:
name = proc.name()
except Exception:
# Getting the process name may fail (e.g. zombie process on macOS)
if name == 'borg' or name.startswith('python'):
if 'mount' not in proc.cmdline():
continue
for idx, parameter in enumerate(proc.cmdline()):
if parameter.startswith(repo_url + '::'):
archive_name = parameter[len(repo_url) + 2:]
# The borg mount command specifies that the mount_point
# parameter comes after the archive name
if len(proc.cmdline()) > idx + 1:
mount_point = proc.cmdline()[idx + 1]
mount_points[archive_name] = mount_point
break
except psutil._exceptions.ZombieProcess:
# Getting process details may fail (e.g. zombie process on macOS)
# Also see https://github.com/giampaolo/psutil/issues/783
continue
if name == 'borg' or name.startswith('python'):
if 'mount' not in proc.cmdline():
continue
for idx, parameter in enumerate(proc.cmdline()):
if parameter.startswith(repo_url + '::'):
archive_name = parameter[len(repo_url) + 2:]
# The borg mount command specifies that the mount_point
# parameter comes after the archive name
if len(proc.cmdline()) > idx + 1:
mount_point = proc.cmdline()[idx + 1]
mount_points[archive_name] = mount_point
break
return mount_points