python - Object of type NoneType using threads -
i have following class
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 queue job has been done if self.pbar: self.pbar.update(self.pbar.currval + 1) self.queue.task_done()
msrun iterator on spectrum objects created class reader:
msrun = pimzml.run.reader(file_imzml, file_ibd, msn_precision = 250e-6)
each spectrum object has attribute list will(initially []) contains intensities (float values). main function contain this:
number_spectra = len(msrun) print "start creating image spectra..." pbar = progressbar( maxval = number_spectra ).start() #spawn pool of threads, , pass them queue instance image_infos = [] in range(number_spectra): t = spectraprocessing(queue, pbar, image_infos) t.setdaemon(true) t.start() #populate queue data spectrum in msrun: queue.put(spectrum) #wait on queue until has been processed queue.join()
get_spectruminfos(spectrum)
function called run method, handles (fill list intensities, ...) list of intensities of each spectrum. when execute error list of intensities nonetype (i.e.; empty), times execution doing without error. without using threads there no error.
thank lot.
Comments
Post a Comment