1

I have a python script that besides other stuff does this:

        #turn all lights 3 on
        for val in EntranceFloodLights:
            time.sleep(timeBetweenSwitches) #delay between switches for overload
            GPIO.setup(val, GPIO.OUT) 
            GPIO.output(val, GPIO.LOW) # set LOW to switch ON

        #save TSLA
        f= open("lastActivation.txt","w+")
        f.write( "%s" % timeNow)
        f.close()

        #set delay for lights to go off in timeToStayOn
        time.sleep(timeToStayOn)

        for val in currentStatus:

            time.sleep(timeBetweenSwitches) #delay between switches for overload

            if currentStatus[val] == 0:
                GPIO.setup(val, GPIO.OUT)
                GPIO.output(val, GPIO.HIGH) # set HIGH to switch OFF

When i run this through shell, it works perfectly,
Unfortunately, when i run it through the web page i set up to control my lights, it does turn off the light, but stops somewhere before writing the file i ask it to.
Any ideas on what i'm missing?
Keep in mind this is my first python script, so i am a total newbie on this.

Thanks in advance

closed as unclear what you're asking by goldilocks May 12 '17 at 15:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please explain in detail: 1) Exactly how this is executed by what web server, 2) Exactly where "somewhere before writing the file" is; you should be able to determine this with debug logging yourself. – goldilocks May 12 '17 at 15:03
  • 1
    Whenever I have a problem like this I immediately suspect the file open statement. i.e., while I am testing I am probably in the correct directory and it works perfectly. Yet then while running it in another environment (cron or apache), I find I need to plan on it starting from a different current directory. Therefore, often these kinds of problems can be solved in Python by giving a fully-qualified filename in the open statement just to be sure it can find it. – SDsolar May 12 '17 at 16:48
  • Thanks SDsolar, will try full paths out and come back to you – krasatos May 15 '17 at 12:39