I have edited ~/.config/lxsession/LXDE-pi/autostart
using nano
(without sudo
) to open a lxterminal and run a simple python script that contains an infinite while loop with a print statement.
In my autostart file I have the following command:
@lxterminal -e python3 ~/Desktop/t.py
However, whenever I boot into Desktop environment, I see a lxterminal window pop up for a split second then disappear.
When I also add @lxterminal -e python3 -v
into the autostart
file, it runs perfectly and the lxterminal window stays there.
I have changed t.py to have one line: print('hello'). The result is the same. A terminal window will open for a split second then close. I don't believe a print statement should cause an exception.
Does anyone know what could be causing my issue?
Thanks
2 Answers 2
With lxterminal -e python3
you are starting the python3 interpreter and it prompts you with >>>
. It is still running until you quit it with <Ctrl>D
. Then the lxterminal will also close. Your hello
script just prints it and terminates and with it also lxterminal. That is what you see but it is too short to realize the hello output. For testing make your t.py as following:
from time import sleep
print('hello world')
while True:
sleep(60)
with the endless while
loop the script does not terminate and will stay in lxterminal until you interrupt it with <Ctrl>C
. Then lxterminal also closes.
-
The OP claims that they have an "infinite while loop with a print statement". In my understanding, an infinite loop cannot be too short.Dmitry Grigoryev– Dmitry Grigoryev2018年11月15日 08:15:46 +00:00Commented Nov 15, 2018 at 8:15
-
@DmitryGrigoryev I refer to the comment only using
print('hello')
. You have already commented it. I have edit the question and add the comment to clarify this.Ingo– Ingo2018年11月15日 09:07:14 +00:00Commented Nov 15, 2018 at 9:07
Edit the local autostart file:
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
Add the following with full paths to python3 and your code:
@lxterminal -e /usr/bin/python3 /home/pi/Desktop/t.py
t.py
so that it will run without error in python 2.7 and try rebootingprint('hello')
. The result is the same. A terminal window will open for a split second then close. I don't believe a print statement should cause an exception.