1

I wrote a PyQt5 GUI (Python 3.5 on Win7). While it is running, its GUI is not responsive. To still be able to use the GUI, I tried to use QThread from this answer: https://stackoverflow.com/a/6789205/5877928

The module is now designed like this:

class MeasureThread(QThread):
    def __init(self):
        super().__init__()

    def get_data(self):
        data = auto.data

    def run(self):
        time.sleep(600)
        # measure some things
        with open(outputfile) as f:
             write(things)

class Automation(QMainWindow):

[...]

    def measure(self):
       thread = MeasureThread()
       thread.finished.connect(app.exit)

       for line in open(inputfile):
           thread.get_data()
           thread.start()

measure() gets called once per measurement but starts the thread once per line in inputfile. The module now exits almost immediately after starting it (I guess it runs all thread at once and does not sleep) but I only want it to do all the measurements in another single thread so the GUI can still be accessed.

I also tried to apply this to my module, but could not connect the methods used there to my methods: http://www.xyzlang.com/python/PyQT5/pyqt_multithreading.html

The way I used to use the module:

class Automation(QMainWindow):

[...]

    def measure(self):
       param1, param2 = (1,2)

       for line in open(inputfile):
           self.measureValues(param1, param2)

    def measureValues(self, param1, param2):
        time.sleep(600)
        # measure some things
        with open(outputfile) as f:
             write(things)

But that obviously used only one thread. Can you help me to find the right method to use here( QThread, QRunnable) or to map the example of the second link to my module?

Thanks!

Community
  • 1
  • 1

0 Answers0