Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raspberry Pi Python (Kivy) extremely slow with sudo

I've been writing a Kivy graphical program on Raspberry Pi, with the KivyPie OS (Linux pre-configured for Kivy development).

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.

I need to use sudo to access Raspberry's GPIO. (unless I try some other way to do it, that I see people discuss).

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: Running the same program on my PC (Linux) with and without sudo doesn't seem to cause such problem. Only on Raspberry.

like image 759
XArgon Avatar asked Aug 03 '15 11:08

XArgon


1 Answers

The problem is that Kivy is using an alternative config.ini file for the root user and not the one you have in ~/.kivy/config.ini.

At the top of your python file you can add the following to force it to use the egl_rpi window:

import os
os.environ['KIVY_WINDOW'] = 'egl_rpi' 

Alternatively, you can copy your ini file over to the root using:

sudo cp ~/.kivy/config.ini /root/.kivy/config.ini

like image 195
Chris Zeh Avatar answered Oct 20 '22 14:10

Chris Zeh