Raspberry Pi Python (Kivy) extremely slow with sudo(Raspberry Pi Python (Kivy) 使用 sudo 非常慢)
问题描述
我一直在使用 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 非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Raspberry Pi Python (Kivy) 使用 sudo 非常慢
基础教程推荐
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
