User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Autorun Python

Sun Oct 21, 2012 8:34 am

How can I get a Python program to run on startup?
No keyboard or monitor, just boot the RPi and away it goes.
Apple say... Monkey do !!

eyebee
Posts: 35
Joined: Tue Sep 25, 2012 7:05 pm
Location: Los Angeles, CA

Re: Autorun Python

Sun Oct 21, 2012 9:33 am


KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Autorun Python

Sun Oct 21, 2012 1:18 pm

Just hacked this problem the other day. Answer based on this https://github.com/wireload/screenly-os ... install.sh

Create the folder home/pi/.config/lxsession/LXDE/

/home/pi/.config is already present in the image but you will need to select Show Hidden files in the Filemanager to see it.

In this folder put a file named autostart with one line:

python /home/pi/myprog.py
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

milhouse
Posts: 621
Joined: Mon Jan 16, 2012 12:59 pm

Re: Autorun Python

Sun Oct 21, 2012 1:35 pm

Which OS? Presumably Raspbian - in which case adding an init.d script is the preferred solution though if you don't require much control over starting/stopping your script and/or just want a really simple solution, then just add the following to the end of /etc/crontab - it will ensure the script starts at startup (running as user root, which you may or may not want, so consider changing that too):

Code: Select all

@reboot root /path/to/python/script.py

beautifulsmall
Posts: 20
Joined: Mon Jun 04, 2012 9:57 pm

Re: Autorun Python

Sat Nov 17, 2012 6:44 pm

How do I stop Autorun.
Hope this is relevant to the topic , I have a C programme a.out to send data out of the uart and i autologon and autorun the programme by an added line /root/Desktop/a.out in /etc/local.rc
It runs ok from power on but how can I stop it . The only thing that works is Ctrl-alt-del which reboots !!
running raspbian, I can see text but no prompt.

beautifulsmall
Posts: 20
Joined: Mon Jun 04, 2012 9:57 pm

Re: Autorun Python

Sat Nov 17, 2012 9:10 pm

rc.local , was the file which runs a.out , the uart sends the data so I know a.out is running but I don't get a prompt and cant get "back in" . any help appreciated.

BlackJack
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
Contact: Website

Re: Autorun Python

Sat Nov 17, 2012 10:27 pm

@beautifulsmall: Any chance you did not start the program asynchronously from ``/etc/rc.local`` so that skript never comes to an end and blocks the startup process‽

Can you stop the program by pressing Ctrl + C at the text screen to get to the text prompt?

Code: Select all

while not self.asleep():
    sheep += 1

beautifulsmall
Posts: 20
Joined: Mon Jun 04, 2012 9:57 pm

Re: Autorun Python

Sun Nov 18, 2012 9:01 pm

The code runs in a continuous loop bursting 8 bytes every second. Ctrl C displays C^ but has no effect. I can use a linux machine tomorrow to edit the file on the SD card so all is not lost and I will add your suggested code. Many thanks.

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 4 guests