1

I have method in my tkinter application. This method is used to export data into CSV from another application. The loop for export the data is very heavy. It takes days of time to complete.

I just came across the multi threading concept. Its kind of difficult to understand, I spent an entire day on this but couldn't achieve anything. Below is the code I use in my loop. Can this be handled by multiple threads without freezing my tkinter UI?

I have a Label that shows the number of records(cells) exported, in the tkinter window.

def export_cubeData(self):
    exportPath = self.entry_exportPath.get()

    for b in itertools.product(*(k.values())):
        self.update()
        if (self.flag == 0):
            list1 = list()
            for pair in zip(dims, b):
                list1.extend(pair)
            list1.append(self.box_value.get())
            mdx1 = mdx.format(*temp, *list1)
            try:
                data = tm1.cubes.cells.execute_mdx(mdx1)
                data1 = Utils.build_pandas_dataframe_from_cellset(data)
                final_df = final_df.append(data1)
                cellCount = tm1.cubes.cells.execute_mdx_cellcount(mdx1)
                finalcellCount = finalcellCount + cellCount
                self.noOfRecordsProcessed['text'] = finalcellCount
            except:
                pass
        else:
            tm.showinfo("Export Interrupted", "Data export has been cancelled")
            return
    final_df.to_csv(exportPath)
    print(time.time() - start)
    tm.showinfo("info", "Data export has been completed")
    self.noOfRecordsProcessed['text'] = '0'
user1404
  • 179
  • 1
  • 3
  • 10
  • The technique used in this [answer](https://stackoverflow.com/questions/53696888/freezing-hanging-tkinter-gui-in-waiting-for-the-thread-to-complete/53697547#53697547) to a question titled "Freezing/Hanging tkinter Gui in waiting for the thread to complete" may be helpful. – martineau Mar 23 '19 at 21:12

0 Answers0