我有两个进程正在运行
exeAPI(在后台运行nohup)
tail -f server.log 输出远程服务器日志
我能够成功将输出刷新到我的python客户端控制台,如下所示:
@bp.route('/executeAPI', methods=['GET', 'POST'])
def executeAPI():
...
(ssh set up params)
print('started...')
data_buffer = ""
stdin_run, stdout_run, stderr_run = client.exec_command('nohup echo source "exeAPI" | nc 127.0.0.1 40000 &')
stdin, stdout, stderr = client.exec_command('tail -n 1 -f /home/server.log', get_pty=True)
for line in iter(lambda: stdout.readline(1024), ""):
data_buffer += line
print(line, end="")
if not data_buffer: # never hits this if statement
print('No more data')
break
print('finished.')
client.close()
return data_buffer
但是,它永远不会for loop在输出完成后退出。
for loop没有换行符时,我该如何突围?
相关分类