Python Forum
Error message when running autostarted code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error message when running autostarted code
#1
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.
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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!
Reply
#4
im using python 2.7 and same EOF message error occured untill i changed the line 15 input function to raw_input(), not input
Reply
#5
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 626 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 379 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 518 Nov-10-2023, 08:09 AM
Last Post: akbarza
  error "cannot identify image file" part way through running hatflyer 0 662 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Error message about iid from RandomizedSearchCV Visiting 2 1,006 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Error when running kivy on python janeik 8 2,028 Jun-16-2023, 10:58 PM
Last Post: janeik
  Another Error message. the_jl_zone 2 973 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Getting error when running "MINUS" between 2 databases marlonbown 4 1,258 Nov-10-2022, 05:49 AM
Last Post: deanhystad
  Code running many times nad not just one? korenron 4 1,356 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,711 Jul-01-2022, 02:51 PM
Last Post: maiya

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020