python multiprocessing scheduling task -
i have 8 cpu core , 200 tasks done. each tasks isolate. there no need wait or share result. i'm looking way run 8 tasks/processes @ time (maximum) , when 1 of them finished. remaining task automatic start process.
how know when child process done , start new child process. first i'm trying use process(multiprocessing) , it's hard figure out. try use pool , face pickle problem cause need use dynamic instantiate.
edited : adding code of pool
class collectorparallel(): def fire(self,obj): collectorcontroller = collectorcontroller() collectorcontroller.crawltask(obj) def start(self): log_to_stderr(logging.debug) pluginobjectlist = [] pluginname in self.settingmodel.getallcollectorname(): name = pluginname.capitalize() #get plugin class , instanitiate object module = __import__('plugins.'+pluginname,fromlist=[name]) pluginclass = getattr(module,name) pluginobject = pluginclass() pluginobjectlist.append(pluginobject) pool = pool(8) jobs = pool.map(self.fire,pluginobjectlist) pool.close() print pluginobjectlist
pluginobjectlist got
[<plugins.name1.name1 instance @ 0x1f54290>, <plugins.name2.name2 instance @ 0x1f54f38>]
picklingerror: can't pickle : attribute lookup builtin.instancemethod failed
but process version work fine
warning kinda subjective deployment , situation current setup follows
i have worker program, fire 6 copies (i have 6 cores). each worker following;
- connect redis instance
- try , pop work of specific list
- pushes logging information
- either idles or terminates on lack of work in 'queue'
then each program standalone while still doing work require separate queuing system. have no go-between on processes, might solution problem.
Comments
Post a Comment