[Python] SystemError: initialization of _GPIO failed without raising an exception

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a basic python script that toggles the state of a GPIO pin on a raspberry pi 4 running osmc (however the problem was replicated on libreelec).

    The purpose of the script is to control a led chaser circuit that will activate when media on Kodi is played. So the pin that its connected to (in this case 11) needs to remain on once the code finishes and exits.

    The script works perfectly and indefinitely through an shh logon via terminal and also works via for the first 10 or so times via keymap entry on osmc Kodi. after around 10 times toggling it crashes the whole os though with this error message:


    EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
    Error Type: <class 'SystemError'>
    Error Contents: initialization of _GPIO failed without raising an exception
    Traceback (most recent call last):
    File "/home/osmc/scripts/pin_toggle.py", line 4, in <module>
    import RPi.GPIO as GPIO
    File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
    SystemError: initialization of _GPIO failed without raising an exception
    -->End of Python script error report<--


    the current .py files code is:


    #!/usr/bin/python

    try:
    import RPi.GPIO as GPIO


    except RuntimeError: print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(11, GPIO.OUT)

    GPIo_Output(11, not GPIO.input(11))


    and the keymap xml that calls the script is:


    <global>
    <keyboard>
    <q>RunScript("/home/osmc/scripts/pin_toggle.py")</q>
    </keyboard>
    </global>

    <Home>
    <keyboard>
    </keyboard>
    </Home>


    Am I doing something fundamentally stupid or is there a fix to this?

    I appreciate that this question may make more sense to me on writing so if you think you can help but don't understand my issue please just ask for clarification

    I tried a bunch of things to do with the python script directly but as I put more including try blocks, etc but Im sure the issue has something to do with the way Kodi is handling the RunScript() via the xml keymap as the script is unbreakable via ssh login on terminal.

    Continue reading...

Compartilhe esta Página