我一直在使用 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.
以下是重点:
总结一下,一开始问题的原因已经找到了,目前还没有找到直接用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 非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!