Cleanup control master sockets in parallel

This commit is contained in:
Kovid Goyal 2022-03-10 12:59:38 +05:30
parent 31d9db7e74
commit 4013544efb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -350,11 +350,16 @@ def cleanup_ssh_control_masters() -> None:
import glob
import subprocess
try:
files = glob.glob(os.path.join(runtime_dir(), ssh_control_master_template.format(kitty_pid=os.getpid(), ssh_placeholder='*')))
files = frozenset(glob.glob(os.path.join(runtime_dir(), ssh_control_master_template.format(
kitty_pid=os.getpid(), ssh_placeholder='*'))))
except OSError:
return
workers = tuple(subprocess.Popen([
'ssh', '-o', f'ControlPath={x}', '-O', 'exit', 'kitty-unused-host-name'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
for x in files)
for w in workers:
w.wait()
for x in files:
subprocess.run(['ssh', '-o', f'ControlPath={x}', '-O', 'exit', 'kitty-unused-host-name'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
with suppress(OSError):
os.remove(x)