Error message when running autostarted code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error message when running autostarted code (/thread-7957.html) |
Error message when running autostarted code - Python4Mike - Jan-31-2018 I have created a python3 script for use on Raspberry pi 3 (approx. 300 lines of code), this program runs perfectly under the included Terminal utility. ie start Terminal, cd to myDir, enter "python myCode.py BUT when I try to run it automatically at start-up I get an error message part way through the code, first 50 lines of code work ok, error message is "syntax err: unexpected EOF while parsing" I cannot see any code problems at the message pointer. I got the program to run automatically in Terminal at start-up by adding the following code to "/.config/lxsession/LXDE-pi/autostart" Added code = "@lxterminal -e python -i /home/pi/myDir/myCode.py" (added before "@xscreensaver -no-splash" line). The program uses operator keyboard and push button inputs to control a real world, real time, process via GPIO and various relays, switches and motors. Can any one help? I can supply the area of code which produces the error in auto-run mode if needed. RE: Error message when running autostarted code - DeaD_EyE - Jan-31-2018 Your code and the stacktrace are helpful to answer this question. Otherwise it's guessing. I guess, it's a different environment and/or (wrong) interpreter. RE: Error message when running autostarted code - Python4Mike - Jan-31-2018 Hi Unladen Swallow Section of code which creates error message is below: The EOF error traces to the section marked as XXXXX, immediately after entering * at keyboard. #Select required action using the selected Trap Release Table defined in mgc_start( ) def pull( ): while True: global table print ("Table " + (table)) #de-bug code arm1 = ( ) arm2 = ( ) arm3 = ( ) arm4 = ( ) arm1 = 1 #1 = Trap not armed, 0 = Trap armed arm2 = 1 #1 = Trap not armed, 0 = Trap armed arm3 = 1 #1 = Trap not armed, 0 = Trap armed arm4 = 1 #1 = Trap not armed, 0 = Trap armed pull = ( ) pull = input ("\nPRESS '*' TO START SELECTED RELEASE TYPE" "\nPRESS '/' TO RETURN TO 'SELECT RELEASE' " "\nPRESS '-' TO FINISH AND SHUTDOWN SYSTEM\n") XXXXX if pull == ("*"): #Start Trap Release Sequence when PB pressed arm1 = GPIO.input(32) arm2 = GPIO.input(36) arm3 = GPIO.input(38) arm4 = GPIO.input(40) print ("TRAP ARM STATUS = " + str(arm1) + str(arm2) + str(arm3) + str(arm4)) print ("RELEASE TABLE SELECTED = " + str(table)) if not (arm1) and not (arm2) and (str(table) == "1" or str(table) == "2" \ or str(table) == "3"): print ("A") #de-bug code print ("\nPRESS BUTTON TO FIRE 1st Release FROM TABLE " + str(table)) flush_random( ) #go to check if flush selected #mgc_start( ) #de-bug code elif not (arm1) and not (arm2) and not (arm3) and (str(table) == "4" \ or str(table) == "5" or str(table) == "6" or str(table) == "10" \ or str(table) == "12"): print ("B") #de-bug code print ("\nPRESS FIRE BUTTON TO FIRE 1st FROM TABLE " + str(table)) flush_random( ) #go to check if flush selected #mgc_start( ) #de-bug code elif not (arm1) and not (arm2) and not (arm3) and not (arm4) \ and (str(table) == "7" or str(table) == "8" or str(table) == "9" \ or str(table) == "11" or str(table) == "13" or str(table) == "14"): print("C") #de-bug code print ("\nPRESS FIRE BUTTON TO FIRE 1st release FROM TABLE " + str(table)) flush_random( ) #go to check if flush selected #mgc_start( ) #de-bug code else: #Invalid selected release type re number of traps armed and ready print ("INVALID RELEASE TYPE RE TRAPS ARMED AND READY") print ("ARM REQUIRED TRAPS & RESELECT RELEASE TYPE") mgc_start() elif pull == ("/"): #Change request clay release type from previous choice print ("\nRETURNING TO 'SELECT RELEASE TYPE' ") mgc_start( ) #Runs mgc_start( ) code again elif pull == ("-"): #Finished with Trap Control Box, Shut Down System print("\nSHUTING SYSTEM DOWN") print("WAIT UNTIL RUN LIGHT IS OFF BEFORE UNPLUGING POWER") GPIO.output(7, 0) #Trap 1 = 0 GPIO.output(11, 0) #Trap 2 = 0 GPIO.output(13, 0) #Trap 3 = 0 GPIO.output(15, 0) #Trap 4 = 0 GPIO.output(29, 0) #System Ready LED = OFF GPIO.output(31, 0) #Fire Pushbutton Disabled (Safety feature) GPIO.output(33, 0) #Flush Pushbutton Disabled (Safety feature) GPIO.cleanup( ) sys.exit( ) #Finished with Trap Control Box, Shut Down System else: #Invalid request, therefore try again print("\nINVALID INPUT, PRESS '*' OR '/' OR '-' TO CONTINUE") continue #Returns to beginning of pull( ) loop Hi unladen Swallow Sorry re code supplied, all the indents seem to have disappeared during cut and paste Hi DeaD_EyE Sorry I sent reply to "Unladen Swallow instead of to you. This is my first time use of this python problem system so I may get the protocols wrong! RE: Error message when running autostarted code - ka06059 - Feb-02-2018 im using python 2.7 and same EOF message error occured untill i changed the line 15 input function to raw_input(), not input RE: Error message when running autostarted code - Python4Mike - Feb-13-2018 Problem Solved! Manually started LXTerminal will allow the input and use of any keyboard key ie. alpha, numeric & symbols like * But autostarted LXTerminal will not allow the use of symbols like * etc, if you try to enter/use them you get "syntax err: unexpected EOF while parsing" So I changed my code to use only numeric (integer) inputs and all is OK, program runs perfectly. No idea why LXTerminal has different rules depending how it is started. Does anyone know? |