Stack Exchange
Python Multiprocessing Pool not launching jobs
This is Python 2.7. I have tried successfully the documentation code:
from multiprocessing import Pool

def f(x):
    return x*x

if __name__ == '__main__':
    pool = Pool(processes=4)              # start 4 worker processes
    result = pool.apply_async(f, [10])    # evaluate "f(10)" asynchronously
    print result.get(timeout=1)           # prints "100" unless your computer is *very* slow
    print pool.map(f, range(10))          # prints "[0, 1, 4,..., 81]"

Then I developed myself a very simple example unsuccessfully:
import multiprocessing

def run_test_n(n):
    print 'inside test %d' % n
    with open('test%d.log' % n, 'w') as f:
        f.write('test %d ok\n' % n)

def runtests(ntests, nprocs):
    pool = multiprocessing.Pool(processes = nprocs)
    print 'runnning %d tests' % ntests
    print 'over %d procs' % nprocs
    tasks = range(1, ntests + 1)
    results = [pool.apply_async(run_test_n, t) for t in tasks]
    for r in results:
        r.wait()

if __name__ == '__main__':
    runtests(5,5)

In this example, no files are created and no 'inside test...' string is printed.
It's as if run_test_n is never called (it actually never is). Why?

You are wrong in results = [pool.apply_async(run_test_n, t) for t in tasks]; the correct form is results = [pool.apply_async(run_test_n, (t, )) for t in tasks]

@PauloJ.Matos pool.apply_async(function_name, argv = (arg1, arg2,...,)). The second parameter should be a tuple, and the last comma should not be ignored. If you have wrong para list, there will be no warning and exception.

You're right but I do find it strand you need the last comma in the tuple.
