[英]Stuck in while True loop python
I am stuck in a while True loop which I can't seem to break, any suggestions please: 我陷入了一段时间的True循环,似乎无法中断,请提出任何建议:
command1 = transporterLink + " -m verify -f " + indir1 + " -u " + username + " -p " + password + " -o " + indir1 + "/VerifyLog.txt -s " + provider1 + " -v eXtreme"
master, slave = pty.openpty()
process = Popen(command1, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
while True:
wx.Yield()
line = stdout.readline()
print line.rstrip()
if not line:
break
process.wait()
The simplest explanation is that you never get an empty line from stdout
. 最简单的解释是,您永远不会从stdout
得到空白行。 Note that print line.rstrip()
does not modify line
; 注意print line.rstrip()
不会修改line
; for example, if the last line ended with a newline, the loop would continue. 例如,如果最后一行以换行符结束,则循环将继续。
Sorted. 排序。 I know that at the end of the last line it will return one of two strings so just needed to search for either of these two: 我知道在最后一行的末尾它将返回两个字符串之一,因此只需要搜索这两个字符串之一即可:
process = Popen(command1, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
while True:
wx.Yield()
line = stdout.readline()
line = line.rstrip()
print line
if "Returning 1" in line:
break
if "Returning 0" in line:
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.