Qt (PySide) application stops working after several days
-
Hi,
I have an interesting problem with Python Qt (PySide) application running on linux. App contains about 10-20 active threads, a lot of timers and signals. After some period of usage (several days), the application stops working - application remains running, but it seems like at that moment all timers and signals stop working. I have created a thread responsible only for writing a simple message to log every 10 seconds and at the moment when the error occurs it also stops with writing to log. I have checked the system status, and everything seems OK (a lot of available RAM). Python doesn't raise any errors neither Qt writes any error or warning messages to the console.
Did anybody encounter a similar problem? Is there any limit on a number of emitted signals? Does Qt produce some logs or can I enable some Qt debug mode? Any suggestion on how to debug a problem like this is welcome.
I am running Python 2.7.12, PySide version 1.2.2 and QtCore version 4.8.7 on Linux Mint 18.1 Serena - Cinnamon 64-bit (based on Ubuntu 16.04).
Thanks in advance.
-
Hi,
I have no experience with PySide 1 so those are just questions/ideas to try to find the issue.
Are you creating new threads regularly ?
Are you creating files ? If so are you closing them properly ?
Is it a 32 bit application running in your 64 bit system ?On a side note, Qt 4 has reached end of life a long time ago and PySide 1 as well. If possible, you should consider updating to Qt 5 and PySide 2 which just got released.
-
Thank you for your answer.
Are you creating new threads regularly ?
I'm not sure what is the regular way of creating threads so I'll give a short example at the end of the post to demonstrate the way I use threads.
Are you creating files ? If so are you closing them properly ?
I am not creating files.
Is it a 32 bit application running in your 64 bit system ?
I am running application on 64 bit system, but I'm not sure about the application. How can I check if a PySide application is 32 bit or 64 bit?
On a side note, Qt 4 has reached end of life a long time ago and PySide 1 as well. If possible, you should consider updating to Qt 5 and PySide 2 which just got released.
I will definitely consider updating application to Qt 5 and PySide 2, but it will take some time.
Example code:
import time import sys from PySide import QtGui, QtCore class ExampleThreadWorker(QtCore.QObject): start_work = QtCore.Signal() work_finished = QtCore.Signal() def __init__(self, worker_name, *args, **kwargs): super(ExampleThreadWorker, self).__init__(*args, **kwargs) self.worker_name = worker_name self.start_work.connect(self._do_some_work) self._thread = QtCore.QThread() self.moveToThread(self._thread) self._thread.start() def do_some_work(self, ): self.start_work.emit() def _do_some_work(self): time.sleep(5) print('Worker {} finished with work.'.format(self.worker_name)) self.work_finished.emit() class MainWindow(QtGui.QWidget): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.worker_1 = ExampleThreadWorker('Worker 1') self.worker_2 = ExampleThreadWorker('Worker 2') self.worker_3 = ExampleThreadWorker('Worker 3') self.worker_4 = ExampleThreadWorker('Worker 4') self.worker_5 = ExampleThreadWorker('Worker 5') self.worker_1.do_some_work() self.worker_2.do_some_work() self.worker_3.do_some_work() self.worker_4.do_some_work() self.worker_5.do_some_work() if __name__ == '__main__': app = QtGui.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
-
@nekitamtip said in Qt (PySide) application stops working after several days:
I'm not sure what is the regular way
I think what @SGaist means is: do you create threads again and again during life-cycle of your app?
"How can I check if a PySide application is 32 bit or 64 bit" - you can check which Python is used (32/64 bit). You can check the Qt libraries packaged with PySide.
I don't think it is a good idea if an object moves itself to another thread!
self.moveToThread(self._thread) self._thread.start()
-
do you create threads again and again during life-cycle of your app?
No, I create threads at the app init and then use them when needed. Also, I have checked Python and it is 64 bit.
I don't think it is a good idea if an object moves itself to another thread!
I will try moving
moveToThread()
andthread.start()
methods outside of thread objects and see if an app works better after it. -
Depending on what your threads are doing, maybe QtConcurrent could be of interest.