Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 318
silverAndroid Avatar asked Aug 07 '15 18:08

silverAndroid


1 Answers

p = Process(target=main, args=p_number)

args needs to be a tuple, but you're giving it an integer. Try:

p = Process(target=main, args=(p_number,))
like image 60
Kevin Avatar answered Oct 06 '22 01:10

Kevin