简体   繁体   中英

How to load large pkl file in pytq window?

I have to load very huge pandas dataframe stored in a local HDD when PyQt GUI is loaded.

The problem is, GUI window hangs until loading huge file is finished.

The below is my sample code.

I think my hanging problem can be solved by using thread and progressbar window.

But, most thread examples I found are using global functions and variables.

In my situation, self.pkl.file should have loaded data. So I should find proper way to toss instance to thread class/function.

I hope you to introduce several sample code or guideline for my situation.

Thank you in advance.

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

import sys 
from PyQt4 import QtGui 
import pandas as pd 

class Pkl(): 
    def __init__(self): 
        self.file = pd.read_pickle('file.dat') 


class MyWindow(QtGui.QMainWindow): 
    def __init__(self, parent=None): 
        super(MyWindow, self).__init__(parent) 

        self.setWindowTitle('MyWindow') 
        self.show() 
        self.pkl = Pkl() 
    def close_application(self): 

        self.close() 




def main(): 

    app = QtGui.QApplication(sys.argv) 
    GUI = MyWindow() 

    ''' 
    w = QtGui.QWidget() 
    w.resize(250, 150) 
    w.move(300, 300) 
    w.setWindowTitle('Simple') 
    w.show() 
    ''' 

    sys.exit(app.exec_()) 


if __name__ == '__main__': 
    main()

You need should use QtCore.QThread, on your case pass it the "pkl" object that should be read on the threading code. Then you need to emit a signal from your thread when the read is complete. That signal is connected to your main class/main thread, which will have access to the pkl object and can update the GUI as required.

For the code check. Updating GUI elements in MultiThreaded PyQT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM