P
P
pypyshka2016-10-05 10:57:25
Python
pypyshka, 2016-10-05 10:57:25

How to understand the cause of a program crash while a thread is running?

Good afternoon. Please help me find the cause of the program crashes. I am using Python 3.4.4 and PyQt 4.11.4. The program has an interface with QTableView, where data is loaded from the Sqlite database and several checkboxes that include additional columns in the table. A timer also starts a thread in which the site is parsed and information is stored in the database. Everything works fine as long as you don't touch anything. If at the moment of starting the stream or when the site is being parsed during the stream, quickly change the size of the main window (increase and decrease the size with the mouse), quickly scroll the table (vertically or horizontally), quickly turn on / off checkboxes, then the program simply crashes. If you follow the same steps, only slowly, then everything works without problems. The exception is window resizing: the program crashes at any speed of resizing, if a thread is running at that time. Where to dig?
Program code:

def check_connect():
    try:
        site_connect = HTTPConnection("test.ru")
        site_connect.request("GET", "/")
        site_connect.close()
    except ConnectionRefusedError:
        return False
    except TimeoutError:
        return False
    except ConnectionError:
        return False     
    else:
        return True
    
def checkBox_db():
    stateCB = main_window.checkBox_1.isChecked()
    stateCB_2 = main_window.checkBox_2.isChecked()
    stateCB_3 = main_window.checkBox_3.isChecked()
    if stateCB is True and stateCB_2 is True and stateCB_3 is True:
        DB_connect = QtSql.QSqlDatabase.addDatabase("QSQLITE")
        DB_connect.setDatabaseName("database.db")
        DB_connect.open()
        cb_model = QtSql.QSqlQueryModel(parent=None)
        cb_model.setQuery("SELECT * FROM table")
    main_window.tableView.setModel(cb_model)
    DB_connect.close()
    ...
  
class check_docs_cl(QtCore.QThread):
    def __init__(self, parent=None):
        QtCore.QThread.__init__(self, parent)
    
    def run(self):
        check_connect()
        if check_connect():
            '''парсинг сайта'''

class docsTimer(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.basictimer = QtCore.QBasicTimer()
        self.basictimer.start(600000, self)        

    def timerEvent(self, QTimerEvent):
        check_docs.start()

class main_cl(QtGui.QMainWindow):
    def __init__(self):
        super().__init__()         
            uic.loadUi("main.ui", self)       

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main_window = main_cl()
    check_docs = check_docs_cl()
    main_window.checkBox_1.stateChanged.connect(checkBox_db)
    main_window.checkBox_2.stateChanged.connect(checkBox_db)
    main_window.checkBox_3.stateChanged.connect(checkBox_db)
    check_connect()
    if check_connect():
        docs_timer = docsTimer()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question