Python multiprocessing pool inside a class -


i want run multiprocessing pool job inside class's function that:

from fuzzywuzzy import fuzz multiprocessing import pool, cpu_count  class findcloasestlocation(resource):     def __init__(self):         self.score = 0.         self.country = ''         self.city = ''      def comparecities(self,location,row):         print 'ss:',row         score = self.comparephrases(location,row[10])         return [score,row[5],row[10]]      def compareresults(self,inputs):         score,country,city = inputs         print 'sc:',score          if score> self.score:             self.score = score             self.country = country             self.city = city      def get(self):         parser = reqparse.requestparser()         parser.add_argument('ws1', type=str, required=true, help="word set 1 cannot blank!", action='append')         args = parser.parse_args()         location = ' '.join(args['ws1'])         print 'location:',location,'--',len(df)         score = 0.         country = ''         city = ''         if len(location)>1:             try:                 pool = pool(processes=cpu_count())                 in df.index:                     pool.apply_async(self.comparecities,(location,df.ix[i],), callback = self.compareresults)                 pool.close()                 pool.join()                 return {'score':self.score,'country':self.country,'city':self.city}              except:                 print 'none!'                 return none         return none     def comparephrases(self,p1,p2):         return fuzz.ratio(p1,p2) 

the problem functions comparecities , compareresults not being called , score value never updated... idea?


Comments