python并行设计的一个失误

不要在进程处理任务时通过process_id来判断哪个进程应该执行任务,因为不知道task会被分配到哪个进程
<pre>
elif command["type"] == "TEST":
print "testing..."
self.env.type = "test"
print "set env"
if self.process_id == 0:
print "enter test"
right_number = 0
for k in xrange(self.pms.test_epoche_size):
print "testing..." + str(k)
path = self.rollout()
labels = path["labels"]
result = self.env.get_prob_result()
calculate_label = np.argmax(result)
if calculate_label == labels[0]:
right_number += 1
self.result_q.put((right_number / self.pms.test_epoche_size))
else:
print str(self.process_id)
</pre>
这种写法是错误的

推荐阅读更多精彩内容