cmd
is a function that process the argument x print the output to stdout. For example, it may be
def cmd(x):
print(x)
A serial program calling cmd()
looks like the following.
for x in array:
cmd(x)
To speed up the program, I'd like it run in parallel. The stdout output can be out-of-order, but the output from a single x must not be broken by the output from another x.
There can be various ways to implement this in python. I figure out something like this.
from joblib import Parallel, delayed
Parallel(n_jobs=100)(delayed(cmd)(i) for i in range(100))
Is this the best way to implement this in python in terms of code simplicity/readability and efficiency?
Also, the above code runs OK on python3. But not on python2, I got the following error. Is it a problem that may cause errors?
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/joblib/externals/loky/backend/semlock.py:217: RuntimeWarning: semaphore are broken on OSX, release might increase its maximal value "increase its maximal value", RuntimeWarning)
Thanks.