Multiprocessing python. Error ''dict' object is not callable' -


i trying multiprocess run method in class. method returns dictionary. not understand why getting error "typeerror: 'dict' object not callable". have seen threads saying instance methods can not pickled , need pickled/unpickled manually. however, not getting error here , wonder why. want multiprocess 1 of instance methods , use result in instance method. attached minimum working example.

            #/usr/bin/python             multiprocessing import pool              class test:                  def __init__(self):                     print "init"                  def  run(self):                     y = {'write_bandwidth': 3768.3135113756257}                     return y                  def pool(self):                     pool = pool(processes=2)                                   result = pool.map(self.run(), range(10))                      print result              if __name__ == '__main__':                 t = test();                 t.pool() 

here error getting.

            init             traceback (most recent call last):               file "/users/preetigupta25/documents/lab work/preeti_repos/preeti_repo/msst_2015/economic-model/src/test3.py", line 20, in <module>                 t.pool()               file "/users/preetigupta25/documents/lab work/preeti_repos/preeti_repo/msst_2015/economic-model/src/test3.py", line 15, in pool                 result = pool.map(self.run(), range(10))                file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/multiprocessing/pool.py", line 250, in map                 return self.map_async(func, iterable, chunksize).get()               file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/multiprocessing/pool.py", line 554, in                 raise self._value             typeerror: 'dict' object not callable             [finished in 0.2s exit code 1] 

the function signature:

 def map(self, func, iterable, chunksize=none): 

this example you:

# coding=utf8 multiprocessing import pool   def f(x):     return x * x   def run(self):     y = {'write_bandwidth': 3768.3135113756257}     return y   if __name__ == '__main__':     p = pool(5)     print(p.map(run, range(3))) 

and result:

[{'write_bandwidth': 3768.3135113756257}, {'write_bandwidth': 3768.3135113756257}, {'write_bandwidth': 3768.3135113756257}] 

if dont understand yet, please click https://docs.python.org/2/library/multiprocessing.html#introduction

good luck!


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -