[cambricon] Resolve infinite loop issue when retrieving logs #738
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1、原始代码说明
在while循环外创建info_line列表,循环内每次间隔300秒访问生成的log文件,并将含有"elapsed time per iteration"字符串的信息append到info_line列表中,只有当列表长度等于迭代步数 getattr(module, "steps") 时跳出while循环。
2、问题说明
当while循环访问到未完成包含所有信息的log时,已有的部分信息仍然会被append到info_line列表;下一次间隔300秒后,会再次将完整的(假设此时log已完成记录所有迭代步)信息append。则列表长度大于getattr(module, "steps"),则一直处于while循环内空转,导致进程无法结束。
3、修改说明
将info_line列表的初始化放在while循环内,每一次append都是独立操作,直到获得完整迭代数,满足跳出while循环条件。