树莓派 Python (Kivy) 使用 sudo 速度非常慢 [英] Raspberry Pi Python (Kivy) extremely slow with sudo

查看:34
本文介绍了树莓派 Python (Kivy) 使用 sudo 速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 KivyPie 操作系统(为 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 运行相同的程序似乎不会导致此类问题.仅在 Raspberry 上.

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.)

这篇关于树莓派 Python (Kivy) 使用 sudo 速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆