Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8013

Python • Re: Python file automatic start up, on booting

$
0
0
Okay, thanx a lot thagrol :) , -now I got the following message in the log file:

“/etc/rc.local: 20: /etc/rc.local: /home/pi/Alarm2_Thread: not found”

I am still working on the SSH connection, but did just try your other suggestion first.
Anyway the: ‘Alarm2_Thread.py’ file is found in the folder: /home/pi/, so I tried to add the “*.py” extension, which just gave the following error:

“/etc/rc.local: 20: /etc/rc.local: /home/pi/Alarm2_Thread.py: Permission denied”

OK.

This is basic stuff that is not in anyway specific to rc.local or other auto start methods.
  • it should have been obvious that the extension (.py) is part of the filename and therefore must be included.
  • Linux file and directory names are also case sensitive. foo.py is not the same file as Foo.py.
  • In order to run a file as a program it must have execute permission set for the user attempting to run it. It would appear that your file does not.
    The simplest and least secure way to add it is

    Code:

    chmod a+x /etc/rc.local: /home/pi/Alarm2_Thread.py
  • Your python file must also have an apropriate shebang as its first line or the shell won't know which interpreter to invoke and pass it to.
    When not using a virtual environment with python I usually use

    Code:

    #!/usr/bin/env python3
The alternative to inserting a shebang and granting execute permission on the fle is to do something like this:

Code:

python -u /etc/rc.local: /home/pi/Alarm2_Thread.py >some.log 2>&1 &
-u tells python not to buffer stdout and stderr. The default buffering can lead to the log file being empty when it shouldn't be. Don't try inserting -u into the shebang I suggested above - that won't work and will just throw an error.

Statistics: Posted by thagrol — Mon May 13, 2024 7:47 pm



Viewing all articles
Browse latest Browse all 8013

Trending Articles