【发布时间】:2018-08-23 10:18:39
【问题描述】:
我正在运行以下代码
try:
child = pexpect.spawn(
('some command --path {0} somethingmore --args {1}').format(
<iterator-output>,something),
timeout=300)
child.logfile = open(file_name,'w')
child.expect('x*')
child.sendline(something)
child.expect('E*')
child.sendline(something))
#child.read()
child.interact()
time.sleep(15)
print child.status
except Exception as e:
print "Exception in child process"
print str(e)
现在,pexpect 中的命令通过从循环中获取输入之一来创建子进程,现在每次启动子进程时,我都会尝试通过 child.read 捕获日志,在这种情况下,它会等待该子进程在再次进入循环之前完成,我如何让它继续在后台运行它(我得到我动态输入的命令输入/输出的日志,但不是此后运行的进程的日志,除非我使用读取或交互?我使用了这个How do I make a command to run in background using pexpect.spawn?,但它使用了interact,它再次等待该子进程完成..因为循环将被迭代几乎超过100次,我不能等待一个完成,然后再移动到另一个,因为pexpect中的命令是一个 AWS lambda 调用,我只需要确保命令被触发,但我无法在不等待它完成的情况下捕获该调用的过程输出......请告诉我您的建议
【问题讨论】:
标签: python amazon-web-services lambda subprocess pexpect