how to solve the problem of the script freezing after restarting the service in paramiko python

24 Views Asked by At

Simple script:

import json
import paramiko
from rich import print, pretty, inspect
from settings import domain
pretty.install()
convert_dom = json.dumps(domain)
set_domain = json.loads(convert_dom)
ip = "250"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
    ssh.connect(set_domain[ip]['host'], port=22, username='root', password=set_domain[ip]['pass'])
except Exception as e:
    print('Ошибка подключения:', e)
    exit()

stdin, stdout, stderr = ssh.exec_command('service mailerq restart')
exit_status = stdout.channel.recv_exit_status()

if exit_status == 0:
    stdout_output = stdout.read().decode("utf-8")
    print(f'STDOUD: {stdout_output}')
    stdout.close()
else:
    stderr_output = stderr.read().decode("utf-8")
    print(f'STDERR: {stderr_output}')
    stderr.close()

stdin.close()
ssh.close()

I'm running it locally. The problem is that after execution the script does not end, but continues to be “executed”. Has anyone encountered this problem? Help me decide.

0

There are 0 best solutions below