0

I'm using PyQt5 for a simple project, during a job the application stops responding and updating progress info.

On linux it continues to work on background and, when the job is finished, it restarts working corretly.

On windows it stops working completly.

How can I make it work?

Here it is some example code of app and gui implementation:

app.py

import sys
from time import sleep
from PyQt5 import QtWidgets

from PyQt5.QtWidgets import QMainWindow
from mygui import Ui_MainWindow


class MyGui(QMainWindow):
    def __init__(self):
        super(MyGui, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.start.clicked.connect(self.dojob)
        self.setFixedSize(self.size())
        self.show()

    def dojob(self, signal):
        for i in range(101):
            self.ui.bar.setValue(i)
            self.ui.bar.update()
            sleep(1)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = MyGui()
    window.show()
    sys.exit(app.exec_())

mygui.py

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mygui.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(462, 72)
        self.widget = QtWidgets.QWidget(MainWindow)
        self.widget.setObjectName("widget")
        self.start = QtWidgets.QPushButton(self.widget)
        self.start.setGeometry(QtCore.QRect(350, 40, 99, 27))
        self.start.setObjectName("start")
        self.bar = QtWidgets.QProgressBar(self.widget)
        self.bar.setGeometry(QtCore.QRect(10, 10, 441, 23))
        self.bar.setProperty("value", 0)
        self.bar.setObjectName("bar")
        MainWindow.setCentralWidget(self.widget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MyGui"))
        self.start.setText(_translate("MainWindow", "start"))

I've edited the post for a better comprehension, I used the 'sleep' to simulate the work that the application has to do. In particular in a first part I launch a web scraper asynchronously:

runner = CrawlerRunner()
deff = runner.crawl(...)
deff.addBoth(lambda _: reactor.stop())
reactor.run()

and later I download some parsed images:

opener = request.build_opener()
opener.addheaders = [('User-Agent', self.AGENTS)]
request.install_opener(opener)
request.urlretrieve(img, img_path)

in both cases the application stops to work and doesn't update progress information.

Thanks in advance.

0 Answers0