0

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

Ingo
  • 42,961
  • 20
  • 87
  • 207
jgv115
  • 117
  • 4

2 Answers2

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.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

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
CoderMike
  • 7,102
  • 1
  • 11
  • 16