Signal slow for the first few times. (Pyqt5)
-
Hi all!
i am facing a strange problem here that I have no clue on how to solve and where it comes from.
i have 2 different thread: the main Thread and another one called the worker.
In the main Thread i emit a signal, that is connected to the slot in the worker thread. here the relevant code:
in my Main.py:
self.thread = QThread() self.worker = worker.Worker() self.worker.moveToThread(self.thread) self.startCameraSignal.connect(self.worker.get_color) self.thread.start(priority=QThread.Priority.HighestPriority) .... self.startCameraSignal.emit(id_c) log.debug("Emitted Start camera 1.3 - " + str(time.time()))
in my worker.py file:
def get_color(self, idin): log.debug("Got Start camera signal - " + str(time.time()))
The code itself works as expected, but i am experiencing the problem that after i reboot the pc, the first time this signal is sent out, the slot sees it only after a few seconds.. anything between 3 and 6 seconds..
after the first time, it works great and it is almost instant.
does anybody have an explanation for this and even better, a way to solve this issue?
Any help is greatly appreciated.
Thank you!
best regards
-
Hi,
This does sound strange.
Which version of PyQt5 are you using ?
On which OS ?
With which version of Python ? -
I am on a Windows 10 IoT Enterprise LTSC system.
To troubleshoot I tried to disable everything:Firewall, Microsoft defender (completely disabled through safe mode), notifications, updates, everything that could be esecuted randomly
python is 3.8.10
pyqt is 5.15.7Thanks for your help
-
PyQt's slot decorator is documented as
reducing the amount of memory used and is slightly faster
. I haven't attempted to verify the statement, but it looks like a cheap experiment to try.Another experiment is to "prime" the worker thread by sending an unrelated signal to determine if the delay is related to the thread, the worker object, or the particular slot.
-
-
@JonB thank you, i am trying the pyside option you posted, but i am having difficulties as i am getting this error: cannot import name 'uic' from 'PySide2'
any idea on what i have to do in this case? i am an occasional python progger and not experienced at all.. thank you
-
@Igor86 said in Signal slow for the first few times. (Pyqt5):
cannot import name 'uic' from 'PySide2'
Unfortunately that is to do with the one major difference between PyQt and PySide if you are using
.ui
file from Designer. I can't remember what you have to change, easy for you if you are a programmer but not if not and I don't use PyQt/PySide regularly to tell you, so you may have to leave this test. Unless a Python person wants to tell you what to alter.... -
@JonB it looks like the problem is here again. but it was indeed away yesterday when i tested it several times.. the only differenche is that now i have enabled the hard disk lock in windows. so am going to investigate if that makes a difference.
-
@Igor86
Hmmm. I hope@pyqtslot
does somehow work for you, just I wonder how it could possibly make a difference of seconds in your situation. I would wonder whether something else might be going on, as you say to do with first time reboot. In your output there isGot Crate ID
between the emission and the receipt, so something else is going on in your code other than what you have shown?"between 3 and 6 seconds" is an enormous delay in computer terms. I find it hard to believe that whatever
@pyqtslot
does it could cost so much without it. If, say, https://stackoverflow.com/a/45842186/489865 or https://stackoverflow.com/a/40330912/489865 or https://www.codeproject.com/Articles/1123088/PyQt-signal-slot-connection-performance are right in their description I can't see how it would achieve that. To me it sounds more like: the slot will only print its output once the processor switches from the worker thread back to the main thread. If something on your system is "very busy" (hardware? memory paging?), first time after reboot, the OS may be unable to do that in a timely manner?