LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2023, 02:51 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 557

Rep: Reputation: 74
pyqt5 GUI very slow to load


Working on a network at my job where I do not have admin access.

The python3 installation does not have the required modules so I install anaconda3 in an area where I have access.

Using the anaconda3 python I have all the modules I need and everything works as expected except that GUI apps are very slow to load - about 10 to 12 seconds. If I shutdown the GUI and immediately restart is loads within a second.

Also get this output when starting the GUI.

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-<USER>'

I can set XDG_RUNTIME_DIR but it does not affect how fast the GUI starts.

I have a home PC with all the required modules included in the system python and the same GUI loads with no 10 to 12 second delay.

Is there anyway to determine the root cause of the delay?
 
Old 04-18-2023, 03:12 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
cProfile
 
Old 04-18-2023, 04:03 PM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
Wrapping cProfile around my main function and the GUI always starts relatively quickly. Logged into several machines and the behavior was consistent. I don't know what cProfile does but it makes trouble shooting this particular issue impossible because the issue cannot be duplicated with cProfile.

I could be wrong (I usually am), but I don't think the issue is with my code because the code runs perfectly on my home PC. It is only on the job network where I see the delay and it is only on a first run, subsequent runs are normal.

EDIT: Testing with cProfile and the GUI starts up normally. Removed cProfile and in the same terminal the GUI loaded slowly.

Last edited by sharky; 04-18-2023 at 04:05 PM.
 
Old 04-18-2023, 05:09 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
Maybe one of the dependencies is large and it's taking forever to load off a slow network share? You can easily test that by just firing up "python3" and typing in the imports.
 
Old 04-18-2023, 05:26 PM   #5
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
All the imports return to the prompt immediately.

My default shell at work is tcsh. I noticed that if I switch to bash to GUI starts up immediately. By 'immediately' I mean no discernible lag at all.

UPDATE: tried bash again and it took about 5 seconds to startup. Still an improvement but the inconsistency is annoying.

UPDATE: tried the import from python prompt again and "from PyQt5 import QtGui, uic, QtCore, QtWidgets" took about 4 to 5 seconds to load.

Last edited by sharky; 04-18-2023 at 05:42 PM.
 
Old 04-18-2023, 05:27 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
Quote:
Originally Posted by sharky View Post
My default shell at work is tcsh.
Working in film production?

Do an "env | sort" in both BASH and tcsh, and then diff the two.

Last edited by dugan; 04-18-2023 at 05:34 PM.
 
Old 04-18-2023, 05:45 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
Sounds like you have a workaround: write a BASH script to launch your Python program.
 
Old 04-18-2023, 05:55 PM   #8
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
Noticed that I can start python3 and enter "from PyQt5 import QtGui, uic, QtCore, QtWidgets" and it takes several seconds to return the prompt.

I then do ctrl-D, immediately start python3, and the import returns to the prompt immediately.

What could cause that? It appears the shell remembers the module imports from the previous python session and keeps them ready. If I wait a long time, not sure how long, before starting python a second time the imports are again slow.
 
Old 04-18-2023, 05:56 PM   #9
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
Quote:
Originally Posted by dugan View Post
Sounds like you have a workaround: write a BASH script to launch your Python program.
Tried that and there was some delay. It also appears that bash periodically has some delay in starting the GUI. However, it is never as slow as tcsh.
 
Old 04-18-2023, 06:19 PM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
Quote:
Originally Posted by sharky View Post
What could cause that? It appears the shell remembers the module imports from the previous python session and keeps them ready. If I wait a long time, not sure how long, before starting python a second time the imports are again slow.
It's certainly because of caching that's done by the filesystem itself.

You know it will become slow if you wait a while. Do that, launch the interpreter with "python3 -v", and do the imports again.

Last edited by dugan; 04-18-2023 at 06:20 PM.
 
Old 04-18-2023, 06:30 PM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,964

Rep: Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217Reputation: 5217
The reason it loads faster in BASH than in tcsh could just be because you're testing in BASH right after testing in tcsh. Be aware of that possibility.

Last edited by dugan; 04-18-2023 at 06:32 PM.
 
Old 04-20-2023, 01:58 PM   #12
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
Noticed this morning that a command line invocation of python took a few seconds to get to the python prompt. Did ctrl-D and immediately restarted python and the prompt appears immediately.

So python itself is slow to load, and import of Qt modules, are both slow on an initial start.

Is there know way to fix this?
 
Old 04-20-2023, 02:38 PM   #13
teckk
Senior Member
 
Registered: Oct 2004
Distribution: Arch
Posts: 4,796
Blog Entries: 6

Rep: Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711
Code:
sysctl vm.drop_caches=3
1st load, python has to load up into RAM.
Code:
time {
    xterm -e "python && quit()"
}

real    0m2.297s
user    0m0.089s
sys     0m0.058s
2nd load with python in RAM.
Code:
time {
    xterm -e "python && quit()"
}

real    0m0.135s
user    0m0.071s
sys     0m0.021s
Code:
cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Core(TM)2 Duo CPU     E7500  @ 2.93GHz
...
You want faster, use a source compiled into executable language like C, C++
 
Old 04-20-2023, 02:56 PM   #14
teckk
Senior Member
 
Registered: Oct 2004
Distribution: Arch
Posts: 4,796
Blog Entries: 6

Rep: Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711Reputation: 1711
atest.py
Code:
#!/usr/bin/python

from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl, QSizeF
from PyQt5.QtPrintSupport import QPrinter

if __name__ == "__main__":
    print (__package__)
    print (__name__)
Code:
sysctl vm.drop_caches=3

#1st
time {
    python3 ./atest.py
}
None
__main__

real    0m2.841s
user    0m0.098s
sys     0m0.083s

#2nd
time {
    python3 ./atest.py
}
None
__main__

real    0m0.114s
user    0m0.087s
sys     0m0.027s
 
Old 04-20-2023, 04:24 PM   #15
sharky
Member
 
Registered: Oct 2002
Posts: 557

Original Poster
Rep: Reputation: 74
Apparently there is no fix. I am still confused why pyqt GUIs start consistently fast on my home system.

teckk, When I get off work I will try your test on work vs home systems.

Thanks,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vobcopy is very very very slow fredak Linux - Software 9 05-03-2013 04:45 PM
Squid Server Very Very Very Slow jatender Linux - Server 1 09-28-2007 11:44 PM
A very very very very big problem!! Elbryan Linux - Software 2 09-23-2005 05:56 AM
Lindows very very very slow jfi Linspire/Freespire 15 03-28-2004 09:06 AM
browsers very very slow to load pages robinmckenzie Linux - Software 0 09-03-2003 04:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration