我有以下课程
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()
get_spectrumInfos(spectrum)
run 方法调用的函数,处理(用强度填充列表,...)每个光谱的强度列表。当我执行时,我收到强度列表为 NoneType (即空)的错误,有时执行没有任何错误。不使用线程就没有错误。
非常感谢。