zulln
zulln

Reputation: 49

Multiprocessing doesn't seems to work at all?

Why doesn't this works? Don't get any error.

I though I had used this snippet of code a year ago and though it worked back then but maybe not.. Using python 2.7

from multiprocessing.pool import ThreadPool

def printer(arg):
    print arg

nThreads = 10

pool = ThreadPool(processes=nThreads)
threads = [pool.apply_async(printer, args=(x)) for x in range(100)]
pool.close()
pool.join()

Upvotes: 1

Views: 154

Answers (1)

Scis
Scis

Reputation: 2974

Changing (x) to (x,) or [x] solves this.

You can easily see what's wrong by running the following code

x = 5 
print type((x))
print type((x,))
print len((x,))

As what apply_async in args is well, args :)

Upvotes: 2

Related Questions