python2.7 in windows | ich füge die mysql connect in die klasse und benutze multiprocessing, erhebe den fehler.python multiprocessing Kann nicht <type 'function'>
self.ispop und self.match_var dict
sprawn_self_calcu zurückzukehren() und unwrap_self_f() ist ein Proxy für die Funktion des Map_class
die Funktion der Selbst Map_class var benötigen.
mein Code wie folgt aus:
from analysis_conf.pop_config import pop_config
import datetime
import multiprocessing
from functools import partial
from sqlalchemy import create_engine
from multiprocessing import Pool as threadpool
def sprawn_self_calcu(arg, **kwarg):
return Map.mapCin(*arg, **kwarg)
def unwrap_self_f(arg, **kwarg):
return Map.mappalg(*arg, **kwarg)
partial_unwrap = partial(unwrap_self_f)
partial_sprawn = partial(sprawn_self_calcu)
class Map:
def __init__(self):
self.ispop = pop_config()
self.match_var = self.ispop.pop_match_var()
def CreateSqlalchemyEngine(self,config):
sigma = 'mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8'%(config['user'],config['passwd'],
config['ipaddr'],config['port'],config['dbname']
)
return create_engine(sigma,pool_recycle=10,pool_timeout=10800)
def Mapping(self,conSet):
self.baseCon = conSet
self.mappalg()
Time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def IUCMapping(self,i,con):
print i
print self.conf
l = con.execute('show tables;')
def mappalg(self):
mt_val = [1,2,3,4,5]
pool = threadpool(4)
result = pool.map(partial_sprawn,zip([self]*5,mt_val))
# result = pool.map(partial_sprawn,zip([self]*mtlen,mt_val))
pool.close()
pool.join()
return True
def mapCin(self,i):
pid_val = multiprocessing.current_process().pid%4
con = self.baseCon[pid_val]
print i
self.IUCMapping(i,con)
return True
class Create_MultiCon:
def __init__(self):
self.adapter = pop_config()
self.conf = self.adapter.pop_baseDB()
self.match_var = self.adapter.pop_match_var()
def CreateSqlalchemyEngine(self,config):
sigma = 'mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8'%(config['user'],config['passwd'],
config['ipaddr'],config['port'],config['dbname']
)
return create_engine(sigma,pool_recycle=10,pool_timeout=10800)
def RdictXcon(self,x):
t = {}
engine = self.CreateSqlalchemyEngine(self.conf)
for i in xrange(x):
t[i] = engine.connect()
return t
if __name__ == '__main__':
l = Create_MultiCon()
conSet = l.RdictXcon(4)
ScMap = Map()
ScMap.Mapping(conSet)
der Fehler:
result = pool.map(partial_sprawn,zip([self]*5,mt_val))
File "C:\Python27\lib\multiprocessing\pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:\Python27\lib\multiprocessing\pool.py", line 567, in get
raise self._value
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
, wie der Fehler multiprocessing
Modul umgehen können nicht mit Funktionen/Methoden solv, die gebeizt kann nicht sein
ich kann‘Verwendung Dill oder Pathos in Fenster –
Does [diese] (http://stackoverflow.com/questions/33293036/pathos-package-in-windows-operating-system) Hilfe ? –
Ich bin der Autor von 'dill',' pathos', 'multiprocess' usw. Die Pakete werden unter Windows getestet und sollten unter Windows funktionieren. Wenn sie nicht für Sie arbeiten, senden Sie bitte ein Ticket an die jeweilige github-Seite und geben Sie an, was Sie gerade sehen. –