I want to run a python program that polls the keyboard on startup/login to my raspberry pi.
Previous attempts included cron jobs (failed due to lack of stdin or stdout).
rc.local also failed as it has no stdin (it got stuck in a perpetual loop - now that was fun to escape)
Hence I've arrived at placing my command into the .profile, and this appears to work well! The program functions exactly as intended when the Pi is turned on but...
When I then try to launch the GUI by
startx, the screen turns black and completely fails to launch. It seems to be something to do with the Ppython program, because when I remove it from the
bash .profile, it all functions fine.
Any help would be massively appreciated!
I created a script that also output to LED's (a simple Red-Yellow-Green sequence) and it appears that .profile is execute again when
startx is run? If so why?
Below is my .profile code, and then my python program; the significance of the python script is (I believe) that it runs a threaded perpetual loop that is terminated by stdin/keyboard
echo "About to run keyboard polling"; sleep 3 python /home/pi/poll_keyboard.py
import thread import time def input_thread(L): key = raw_input() L.append(key) thread.exit() #Should close thread at end def do_print(): L =  thread.start_new_thread(input_thread, (L,)) i = 0 while True: print "Hello World %d" % i if L: #If anything has been detected break i += 1 time.sleep(0.5) return L key = do_print() print "Key press detected: %s. Exiting in 2" % key time.sleep(2) exit()