Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deadlock when calling subprocess.Popen() #194

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vorta/borg/borg_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(self):
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
Expand Down
33 changes: 17 additions & 16 deletions src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,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)
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:]
if name == 'borg' or name.startswith('python'):
if 'mount' not in proc.cmdline():
continue

# 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
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

return mount_points