多重处理:TypeError:"int"对象不可迭代 [英] multiprocessing: TypeError: 'int' object is not iterable
问题描述
我正在Python 3中使用multiprocessing
模块,但是由于某些原因,当我运行该程序时,它会不断抛出TypeError: 'int' object is not iterable
.这就是我所做的:
I'm using the multiprocessing
module in Python 3 but for some reason, it keeps throwing TypeError: 'int' object is not iterable
when I run the program. This is what I did:
def main(i):
global urlDepth
global row
global counter
urlDepth = []
row = 0
counter = 0
login(i)
crawler(MENU_URL)
if __name__ == '__main__':
workers = 2
processes = []
for p_number in range(workers):
p = Process(target=main, args=p_number)
p.start()
processes.append(p)
for p in processes:
p.join()
我不明白为什么会这样,有人可以帮我吗?
I don't understand why this is happening, could someone help me with this?
不是 TypeError的重复项:'int'对象不可迭代因为这是相同的错误,是的,但是原因不同,请在尝试将此问题标记为重复之前先阅读问题/代码.
Not a duplicate of TypeError: 'int' object is not iterable because it is the same error, yes, but it's of a different cause, please read the question/code before trying to mark this question as a duplicate.
推荐答案
p = Process(target=main, args=p_number)
args
必须是一个元组,但您要给它一个整数.试试:
args
needs to be a tuple, but you're giving it an integer. Try:
p = Process(target=main, args=(p_number,))
这篇关于多重处理:TypeError:"int"对象不可迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!