1

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()
zulln
  • 49
  • 4

1 Answers1

2

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 :)

Community
  • 1
  • 1
Scis
  • 2,934
  • 3
  • 23
  • 37
  • Really.. Should have read the docs more carefully. Will mark this as correct when I get home. – zulln Jul 29 '14 at 12:01