I wrote a python GUI program to deal with some scientific calculations. One of the functions was extremely time consuming so that I wish to put it into a separate thread so that running it will not block the entire program.
The problem is that this thread does not actually starts (or queue.get never obtains a result).
However, if I passed the option block = True into the self.PLUQ = self.queue.get(block = False) statement, the function will execute but will also block the entire program.
Class PLUQ_GUI_Dialog():
#somefunctions to initiatialize the class
def guess_button_click_cb(self):
self.selected_peaks = self.session.selected_peaks()
if (not self.is_ready_to_guess()):
return
self.input_frequencies = self.get_input_frequencies(self.selected_peaks)
self.queue = Queue.Queue()
thread = threading.Thread(target = self.guess, args = (self.queue, self.input_frequencies))
thread.setDaemon(True)
thread.start()
self.top.after(100, self.process_queue)
def guess(self, queue, inputs):
PLUQ = pluq.PLUQ_interface()
#pluq is a separate python module
PLUQ.query(inputs)
#query does some calculations and put results in the PLUQ object
queue.put(PLUQ)
def process_queue(self):
try:
self.PLUQ = self.queue.get(block = False)
self.update_pluq_result() # This will display the result
except Queue.Empty:
self.top.after(100, self.process_queue)
#some helper function