python - Multiprocessing pool not working in user defined function -


i wanted implement multiprocessing pool. if bug or mistake not able so. pooling works numpy function while user defined function runs error.

import numpy >>> import multiprocessing >>> p = multiprocessing.pool(5) >>> p.map(numpy.sqrt,range(50))  [0.0, 1.0, 1.4142135623730951, 1.7320508075688772, 2.0, 2.2360679774997898,     2.4494897427831779, 2.6457513110645907, 2.8284271247461903, 3.0, 3.1622776601683795, 3.3166247903553998, 3.4641016151377544, 3.6055512754639891, 3.7416573867739413, 3.872983346207417, 4.0, 4.1231056256176606, 4.2426406871192848, 4.358898943540674, 4.4721359549995796, 4.5825756949558398, 4.6904157598234297, 4.7958315233127191, 4.8989794855663558, 5.0, 5.0990195135927845, 5.196152422706632, 5.2915026221291814, 5.3851648071345037, 5.4772255750516612, 5.5677643628300215, 5.6568542494923806, 5.7445626465380286, 5.8309518948453007, 5.9160797830996161, 6.0, 6.0827625302982193, 6.164414002968976, 6.2449979983983983, 6.324555320336759, 6.4031242374328485, 6.4807406984078604, 6.5574385243020004, 6.6332495807107996, 6.7082039324993694, 6.7823299831252681, 6.8556546004010439, 6.9282032302755088, 7.0] >>> def f(x):       return x*x  >>> p.map(f, range(50)) exception in thread thread-2: traceback (most recent call last): file "c:\python27\lib\threading.py", line 530, in __bootstrap_inner self.run() file "c:\python27\lib\threading.py", line 483, in run self.__target(*self.__args, **self.__kwargs) file "c:\python27\lib\multiprocessing\pool.py", line 285, in _handle_tasks put(task) typeerror: expected string or unicode object, nonetype found 

i thankful, if suggest.

move code .py script, , call python on it.

or if must use python interpreter directly, move f function definition module import (just numpy.sqrt)

it seems when poolworkers spawned, local function definitions (e.g. f, defined in interpreter console) not passed it, complains.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -