... 占位
参考 https://zhiqianghe.blog.csdn.net/article/details/108440342
import paramiko, sys, time import multiprocessing as mp from multiprocessing import Manager from multiprocessing import Queue # 创建SSH对象 def getdf(q): ssh = paramiko.SSHClient() # 允许连接不在know_hosts文件中的主机 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 连接服务器 ssh.connect(hostname='192.168.122.72', port=22, username='uos', password='uosuos') # 执行命令 stdin, stdout, stderr = ssh.exec_command('lsblk') # 获取命令结果 result = stdout.read() # 关闭连接 ssh.close() q.put(result.decode('utf-8')) def Hup(q): time.sleep(2) q.put("Hup=====>") def h(q): print(q.get()) # print(q.get()) def main(): q=Queue() print("main beigin") # p1=mp.Process(target=h,args=(q,)) p2=mp.Process(target=getdf,args=(q,)) # p1.start() p2.start() # p1.join() p2.join() print(q.get()) print("main end") if __name__ == '__main__': main() ------------output------------------- uos@vm3:~/tmp$ python sshh.py main beigin NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 65G 0 disk ├─sda1 8:1 0 1.5G 0 part /boot ├─sda2 8:2 0 1K 0 part ├─sda3 8:3 0 11G 0 part /recovery ├─sda4 8:4 0 3G 0 part [SWAP] ├─sda5 8:5 0 15G 0 part / ├─sda6 8:6 0 15G 0 part └─sda7 8:7 0 19.5G 0 part /data sdb 8:16 0 2G 0 disk └─sdb1 8:17 0 1.9G 0 part sr0 11:0 1 1024M 0 rom main end