我有以下课程
queue = Queue.Queue()
class SpectraProcessing(threading.Thread):
def __init__(self, queue, pbar = None, image_infos = []):
threading.Thread.__init__(self)
self.queue = queue
self.pbar = pbar
self.image_infos = image_infos
def run(self):
while True:
spectrum = self.queue.get()
self.image_infos.append(get_spectrumInfos(spectrum))
#signal to queue job has been done
if self.pbar:
self.pbar.update(self.pbar.currval + 1)
self.queue.task_done()
msrun是使用Reader类创建的Spectrum对象的迭代器:
msrun = pimzml.run.Reader(file_imzML, file_ibd, MSn_Precision = 250e-6)
每个光谱对象都有一个属性列表(最初它是[])包含强度(浮点值)。 我的主要功能包含:
number_spectra = len(msrun)
print "start creating the image from spectra..."
pbar = ProgressBar( maxval = number_spectra ).start()
#spawn a pool of threads, and pass them a queue instance
image_infos = []
for i in range(number_spectra):
t = SpectraProcessing(queue, pbar, image_infos)
t.setDaemon(True)
t.start()
#populate queue with data
for spectrum in msrun:
queue.put(spectrum)
#wait on the queue until everything has been processed
queue.join()
run方法调用的 get_spectrumInfos(spectrum)
函数处理(用强度填充列表,......)每个谱的强度列表。
当我执行时,我得到强度列表为NoneType(即;空)的错误,有时执行没有任何错误。不使用Threads就没有错误。
非常感谢。