Embedding Paramiko with continuous stdout into tkinter GUI (creating SSH command line output in tkinter) Embedding Paramiko with continuous stdout into tkinter GUI (creating SSH command line output in tkinter) tkinter tkinter

Embedding Paramiko with continuous stdout into tkinter GUI (creating SSH command line output in tkinter)


There is actually a very simple solution to this, although it's hard to find a working example!

You need to use ThreadPoolExecutor:

from concurrent import futuresfrom time import sleepthread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)=== the following is part of your class ===def toggle(self):    thread_pool_executor.submit(self.blocking_code)def blocking_code(self):    sin, sout, serr = self.ssh.exec_command('xxxxxxxx')    while not sout.channel.exit_status_ready():        n = len(sout.channel.in_buffer)        if n:            buf = sout.read(n).decode('utf-8')            ##### (output buf to gui)        elif self.my_input:            ##### (gui assigns any string to self.my_input)            sin.write(self.my_input.encode('utf-8'))            self.my_input = ''        else:            sleep(.1)