synchroniser : use with when using Popen

Creating a subprocess with Popen is allocating ressources (according to
pylint) so wrap it in a with to avoid problems.

Also link to unison documentation for the return code value.
This commit is contained in:
2026-05-05 12:11:07 +02:00
parent 8733167ae3
commit 22d30b4df7
+8 -4
View File
@@ -123,7 +123,7 @@ class Synchroniser:
f"{self.remote_user}@{self.remote_ip}",
"-p", str(self.remote_port)
]
master_ssh = subprocess.Popen(command)
with subprocess.Popen(command) as master_ssh:
# TODO: Raise an exception instead of changing the return value
try:
ret_code = master_ssh.wait(timeout=connection_timeout)
@@ -151,8 +151,10 @@ class Synchroniser:
f"{self.remote_user}@{self.remote_ip}",
"-p", str(self.remote_port)
]
close = subprocess.Popen(command)
return close.wait()
with subprocess.Popen(command) as close:
retval = close.wait()
return retval
def sync_files(self, paths:list, force:bool=False) -> None:
"""Synchronises the files.
@@ -254,8 +256,10 @@ class Synchroniser:
for arg in other:
command.append(arg)
proc = subprocess.Popen(command)
with subprocess.Popen(command) as proc:
ret_code = proc.wait()
# See unison manual section 6.11
if ret_code == 3:
raise FatalSyncError("Synchronisation could not be completed")