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


    Code
    1. python /storage/scripts/script-name-here.py.


    The scripts have been added to autostart.sh


    Shell-Script
    1. #!/bin/bash
    2. (python /storage/scripts/script-for-shutdown.py)&
    3. (python /storage/scripts/script-for-encoder.py)&
    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.


    Thanks!

  • 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:

    Code
    1. File "/file/name/here.py, 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:


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