リスト内に新しいジョブを作成するマルチプロセッサ システムを機能させるにはどうすればよいですか? 私は得続けます:
self._popen が None であることをアサートします。「プロセスを 2 回開始することはできません」
私は基本的に同じジョブの複数のインスタンスを作成しているので、これは理にかなっています...どうすれば修正できますか? マルチプロセッサ プールをセットアップする必要がありますか?
もっと明確にする必要がある場合はお知らせください。
ここに私のマルチプロセッシングクラスがあります:
class Worker(multiprocessing.Process):
def __init__(self, output_path, source, file_name):
self.output_path = output_path
self.source = source
self.file_name = file_name
def run(self):
t = HTML(self.source)
output = open(self.output_path+self.file_name+'.html','w')
word_out = open(self.output_path+self.file_name+'.txt','w')
try:
output.write(t.tokenized)
for w in word_list:
if w:
word_out.write(w+'\n')
word_out.close()
output.close()
word_list = []
except IndexError:
output.write(s[1])
output.close()
word_out.close()
except UnboundLocalError:
output.write(s[1])
output.close()
word_out.close()
これは、このすべてを実装するクラスです。
class implement(HTML):
def __init__(self, input_path, output_path):
self.input_path = input_path
self.output_path = output_path
def ensure_dir(self, directory):
if not os.path.exists(directory):
os.makedirs(directory)
return directory
def prosses_epubs(self):
for root, dirs, files in os.walk(self.input_path+"\\"):
epubs = [root+file for file in files if file.endswith('.epub')]
output_file = [self.ensure_dir(self.output_path+"\\"+os.path.splitext(os.path.basename(e))[0]+'_output\\') for e in epubs]
count = 0
for e in epubs:
epub = epubLoader(e)
jobs = []
# this is what's breaking everything right here. I'm not sure how to fix it.
for output_epub in epub.get_html_from_epub():
worker = Worker(output_file[count], output_epub[1], output_epub[0])
jobs.append(worker)
worker.start()
for j in jobs:
j.join()
count += 1
print "done!"
if __name__ == '__main__':
test = implement('some local directory', 'some local directory')
test.prosses_epubs()
これに関する助けをいただければ幸いです。また、自分のコードで行っていることをもっとうまくできるかどうかも教えてください... 私は常に最善の方法で物事を行う方法を学ぼうとしています。