如何在没有堆栈跟踪的情况下调试Python Multiprocessing pool.map()错误(IndexError:字符串索引超出范围)?

sid*_*ise 2 python multiprocessing

在python中从multiprocessing lib使用pool.map()。得到以下错误:

IndexError: string index out of range
Run Code Online (Sandbox Code Playgroud)

是否可能来自超出范围的变量(列表)?如果可以,我该如何调试?没有说明错误发生的位置。

代码的更多说明:

(编辑)

def myFunction(list):
     # function contents
     for item in list:
          # do tasks
with closing(Pool(processes=2)) as pool:
     pool.map(myFunction, sublist)
     pool.map(myFunction2, sublist2)
Run Code Online (Sandbox Code Playgroud)

sid*_*ise 5

答案在于我对该pool.map(func, iterable)方法的误解。

上一个函数myFunction()使用for循环在列表对象中循环。实现后,我将该功能留在了函数中,pool.map()因此由于for循环的缘故,我精心准备的所有任务将更进一步。

解决方案是删除for循环并调整一些代码使其更像这样的简单情况:

def myFunction(list):
    # do tasks
    # for loop contents....
Run Code Online (Sandbox Code Playgroud)

这么简单,但是我没有意识到.map()应该首先使用该方法。感谢@dano指出需要注意的内容。