Script Won't Launch at boot

  • Hello

    I've got two scripts I've written in python with a lot of help I've gotten from various forums and threads. The scripts control a rotary encoder and a shutdown button. Basic stuff. I can ssh into my pi4 and run the scripts in libreelec using the code below, but ONLY one at a time until the script is exited

    1. python /storage/scripts/

    The scripts have been added to

    1. #!/bin/bash
    2. (python /storage/scripts/
    3. (python /storage/scripts/
    4. exit

    I've verified that I ran chmod +x on both files.

    I'm simply at a loss for what I've done wrong. When the scripts are run via the terminal, they seem to work well.

    Any help would be GREATLY appreciated. I'm sure it's something stupid I'm doing.


  • Does it work if you change "python" to "/usr/bin/python" ?

    This didn't seem to have an effect. I thought perhaps my scripts are bad, but if they were they would generate errors no? So I ran the other suggestion

    Use journalctl -u kodi-autostart to see error messages.

    This did produce an error, but one I'm not sure I know how to correct:

    1. File "/file/name/, line 59, in <module>
    2. input("")
    3. EOFError: EOF when reading a line

    same error in both files. This explains why it works when run in the terminal via ssh and not when it's being launched at startup. There is no place to insert an input(at least that's what I'm assuming the issue is based on my understanding of the command). I assumed that the input command was being used to allow the encoder or the button to send information to the system. If this is not the case, what do I need to change? I don't want the script running using a polling method. I thought I figured it all out, had copied some work people had done, and understood what I was doing, now I feel humbled again.

    Any suggestions? Here's a copy of the Rotary Encoder script. I'll leave out the setmode and setup stuff all three variables are GPIO.IN and set to GPIO.PUD_UP

    Edited once, last by LineOfRahl: noticed an error in my copied code! Sorry ().

  • To just wait for the termination exception try to replace the last two lines with something like:

    1. try:
    2. while True:
    3. sleep(100)
    4. finally:
    5. GPIO.cleanup()
  • So this does work, but what impact is this polling going to have on the system resources? So that I understand the while loop embedded in the try method, is this while true value constantly being checked by the system? If there is an action taken at the same time as the while loop is being checked, will it cause any errors? I guess I thought the point of using wait for edge was to avoid while loops. I'm going to be adding another ky040 switch to this device also, so I want to be sure my scripts are efficient. Thank you both for your help so far.

  • A sleep() is never busy. :-)

    Technically now the thread is waiting at a timer event instead of waiting on an input event. I both cases no CPU time is used.

    Feel free to verify the used CPU time with ps or top.