I have a python code that creates a GUI using wx that allows the user to pick a file on their computer and then calls a C function that I wrapped with swig that uses this file and does calculations and saves it to a new file. I want this function call to run in one thread, while the wx window won't stop responding and I also have a loading bar that estimates the amount of time it will take to finish the calculations and updates the progress every second. Currently, the code starts running the loading bar function in a thread, then starts running the calculations in a thread, but this causes the loading bar function to pause. After all of the calculations are done a few minutes later the loading bar function resumes. I want these threads to run in parallel, but I cant get it to work with this wrapped function (other times I've used this threading it has worked).
Part of my code is as follows:
thread.start_new_thread(self.loading_bar, (max_count,))
thread.start_new_thread(self.run_interpolation, (option,))
def loading_bar(self, max_count):
loaded = 1.0
print 180 + (max_count / 2), loaded
while loaded < 100.0:
print 180 + (max_count / 2), loaded
sleep(1)
wx.CallAfter(self.gauge.SetValue, loaded)
loaded += 100.0 / (180 + (max_count / 2))
sleep(2)
wx.CallAfter(self.gauge.SetValue, 0)
def run_interpolation(self, option):
weather_interp.main_func(self.input[1], self.input[2], self.location, option)
I have heard that the multiprocessing modules, and threading modules are better than the thread module, but I don't understand why and trying to use them didn't seem to work either.