How to use threading.Thread() correct.
My code as follow, some time meet UI error.
def get_all_file_size(self, start_path):
total = 0
K, M, G = 1024, 1024**2, 1024**3
MM = 100 * M # 100MB
for path, dirs, files in os.walk(start_path):
for f in files:
fp = os.path.join(path, f)
if os.path.isfile(fp):
size = os.path.getsize(fp)
total = total + 1
if (size > MM):
self.text_multi_text.AppendText(fp + " " + str(float('%.2f' % (size/M))) + "M\n")
self.text_multi_text.AppendText("\nTask is down, check files number: " + str(total))
def OnExecute(self, event):
self.text_multi_text.Clear()
self.text_multi_text.AppendText("More 100M file list\n")
input = self.text_input.GetValue()
# self.get_all_file_size(input)
t1 = threading.Thread(target=self.get_all_file_size, args=(input,))
t1.start()