QApplication constructor taking very long time on Raspberry Pie python3 PyQt5
-
I am investigating extremely slow start of a python3 script running on Raspberry Pi and nailed it down to QApplication constructor. To confirm, I have created TestQt.py:
from sys import argv from PyQt5.QtWidgets import QApplication app = QApplication(argv)
It takes 45-49 seconds to execute, e.g.
pi@raspberrypi:~/test-dir $ time python3 TestQt.py real 0m48.973s user 0m0.394s sys 0m0.106s
While it starts,
top
shows very low CPU usage. Therefore, I suspect some I/O timing out, so it is probably more related to Qt5 than to python.
Have anyone here ever seen anything like that? I would be grateful if you could share any advice, please. -
@Marek-Stocki
I know nothing about Pi [sic.]. But under Linux you may get a idea of what a program is doing, especially when it pauses and you look at the latest line, if you runstrace <your-executable>
, assuming Pi hasstrace
. -
Thanks a lot, Jon. Unfortunately, the strace log shows over 4000 syscalls for this single function call. :-( None of them is individually taking a long time, and they are quite evenly spread in time, just the number is overwhelming. Do you know, if it is typical for QApplication constructior or may indicate a problem?
-
@Marek-Stocki
Hmmm :(This is really beyond my knowledge, you need someone more expert than I to comment....
-
Google
qapplication slow
. There are just a few hits, mostly quite old, but worth reading through each one for ideas. -
I assume you cannot test a C++ application? It only takes a little time to download/setup PySide2, try that to eliminate PyQt5 from being the issue?
-
It won't be this, but do check some non-Qt Python script startup time, just in case.
-
Try the lowest level
QCoreApplication
(no UI) instead ofQApplication
. Any better? -
4,000 syscalls in 40 seconds is 100 per second which is actually quite slow/high per syscall average. If you let the output run in a terminal in realtime you don't see any "pauses" at any point? If you redirect to file you then have to quite some analysis! Edit the file, delete out lines you're not interested in iteratively to try to narrow down. Some syscalls show filepath access, look at those, do they look like reasonable files for startup to look at?
-
What exact version of Qt are you using? Did it come with Pi or did you build yourself (make sure it's a release not a debug build)? Can you try a different version? Can you completely uninstall, check for any remaining Qt artefacts, re-install?
Do you know, if it is typical for QApplication constructior or may indicate a problem?
40 seconds startup indicates a problem! ;-)
-
-
Thanks. I could not install PySide2 on my system, but I have managed to install PySide 1.2.4 that works with python 2.7.16 and Qt 4.8.7. With this setup, the execution time for my TestQt.py script was reduced to ~26 s. It may be OKish for a 600 MHz CPU of the Pi. Next, I will check if our software can be adapted for Python 2.7.
-
@Marek-Stocki
Wait, wait! You absolutely do not want to move a Python3 application back to Python2! Trust me :)Even 26 seconds startup is quite unacceptable. Start up should be like ~1 second!! There is something wrong.....