管理此python异常时出现问题:Can';是否继续下一个迭代/元素?

管理此python异常时出现问题:Can';是否继续下一个迭代/元素?,python,python-3.x,loops,exception,Python,Python 3.x,Loops,Exception,我有一个从xml文档中提取文本的脚本,问题是有一个空xml文件,因此我按如下方式管理: documents_dir = ['../file_1.xml', .....,'../file_N.xml'] try: for f in p.imap_unordered(extract_txt, documents_dir): print('completed file:', f) except ShellError: pass 问题是,不再继续处理下一个文件,而是停

我有一个从xml文档中提取文本的脚本,问题是有一个空xml文件,因此我按如下方式管理:

documents_dir = ['../file_1.xml', .....,'../file_N.xml']

try:
    for f in p.imap_unordered(extract_txt, documents_dir):
        print('completed file:', f)
except ShellError:
    pass
问题是,不再继续处理下一个文件,而是停止for循环的流。我怎样才能继续?请注意,我试图使用
通行证
。然而,它不起作用

更新

或者,我尝试:

try:
    p.imap_unordered(extract_txt, documents_dir)
except ShellError:
    pass

但是,它不起作用。

您需要存储迭代器,以便恢复迭代:

documents_dir = ['../file_1.xml', .....,'../file_N.xml']

results = p.imap_unordered(extract_txt, documents_dir)
while True:
    try:
        for f in results:
            print('completed file:', f)
        break
    except ShellError:
        continue

每次点击
ShellError
,它都会继续无限循环,尝试在同一迭代器上用下一个值重新启动
for
循环;一旦循环自然结束,它就会打破无限循环。如果引发其他无法识别的异常,则当异常冒泡时将退出循环。

感谢@AChampion的帮助。的
行导致了错误。我还可以使用哪种逻辑来达到这种目的?(文件路径列表上的多线程映射)