問題描述
我一直在使用 KivyPie OS(為 Kivy 開發預配置 Linux)在 Raspberry Pi 上編寫 Kivy 圖形程序.
I've been writing a Kivy graphical program on Raspberry Pi, with the KivyPie OS (Linux pre-configured for Kivy development).
由于某種原因,如果使用 sudo 啟動,它的運行速度會非常慢.通常,運行python main.py",程序每秒運行大約 30 個周期.但是,如果我執行sudo python main.py",它會以每 5-10 秒 1 個周期的速度運行.
For some reason, it's running extremely slow if started with sudo. Normally, running "python main.py", the program runs at about 30 cycles per second. However, if I do "sudo python main.py", it runs as slowly as 1 cycle per 5-10 seconds.
我需要使用 sudo 來訪問 Raspberry 的 GPIO.(除非我嘗試其他方法,否則我會看到人們討論).
I need to use sudo to access Raspberry's GPIO. (unless I try some other way to do it, that I see people discuss).
不過,我很感興趣,使用 sudo 導致性能大幅下降的原因可能是什么?有沒有可能解決這個問題?
I'm interested, though, what could be the cause of such a massive performance drop with sudo? And is it possible to work around that?
PS:在我的 PC (Linux) 上運行相同的程序,無論是否使用 sudo,似乎都不會導致此類問題.僅在覆盆子上.
PS: Running the same program on my PC (Linux) with and without sudo doesn't seem to cause such problem. Only on Raspberry.
推薦答案
好吧,我認為這個問題已經解決了,即使還有一些問題.
Well, I would call this problem solved, even if a few questions remain.
以下是重點:
- 速度變慢的原因是 Kivy 無法在sudo"下加載正確的視頻驅動程序,而是使用軟件渲染.
- 我還沒有弄清楚為什么驅動程序沒有加載 sudo 或如何修復它.不過……
- 使用 Pyinstaller 編譯程序后,一切正常.可執行文件可以使用 sudo 啟動,GPIO 正在工作,Kivy 加載了適當的驅動程序,一切都運行得很快,應該如此.
總結一下,一開始問題的原因已經找到了,目前還沒有找到直接用Python啟動程序的解決辦法,但是用Pyinstaller編譯程序解決了這個問題.(不過,這不是一種方便的調試方式.)
To sum it up, the reason of the initial problem has been found, no fix for launching the program directly with Python was yet found, but the problem was removed by compiling the program with Pyinstaller. (still, not a convenient way for debugging.)
這篇關于Raspberry Pi Python (Kivy) 使用 sudo 非常慢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!