mode [ON/OFF]

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
NicoleN
Posts: 10
Joined: Wed Oct 07, 2015 2:59 am

mode [ON/OFF]

Post by NicoleN » Fri Nov 27, 2015 8:05 am

startup value: mode = False

Code: Select all

if mode == False:
    mode = True
    do something
else:
    mode = False
    do something else
This works up to 10 times, then:

Code: Select all

RuntimeError: maximum recursion depth exceeded
any idea how to fix it?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: mode [ON/OFF]

Post by dhylands » Fri Nov 27, 2015 8:14 am

You'd need to provide more information.

You must have something like a function foo that calls itself, or calls something else which calls itself:

Code: Select all

def foo():
    do stuff
    something()
    
def something():
    do stuff
    foo()

NicoleN
Posts: 10
Joined: Wed Oct 07, 2015 2:59 am

Re: mode [ON/OFF]

Post by NicoleN » Fri Nov 27, 2015 8:58 am

Code: Select all

mode_1 = False

def mode1():
    execfile('/flash/mode1.py')
/flash/mode1.py:

Code: Select all

if mode_1 == True:
    mode_1 = False
    pin1.low()
    execfile('/flash/main.py')
else:
    mode_1 = True

def do_stuff():
    pin1.high()

while True:
    if BT.any() == True:
        execfile('/flash/main.py')
    else:
        do_stuff()
mode1() -> pin ON
mode1() -> pin OFF
mode1() -> pin ON
mode1() -> pin OFF
mode1() -> pin ON
mode1() -> pin OFF
...
mode1() -> RuntimeError: maximum recursion depth exceeded

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: mode [ON/OFF]

Post by danicampora » Fri Nov 27, 2015 9:23 am

Ok, maybe I am getting it wrong, but it looks that your main.py calls mode1.py which then calls main.py again, is that correct? If so then you have a recursion there, what's the intention....?

NicoleN
Posts: 10
Joined: Wed Oct 07, 2015 2:59 am

Re: mode [ON/OFF]

Post by NicoleN » Fri Nov 27, 2015 9:56 am

that is correct. Thanks, I ll try to fix it

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: mode [ON/OFF]

Post by dhylands » Fri Nov 27, 2015 6:24 pm

When main1.py gets to the end execution will resume in main.py after the execfile call.

Alternatively you could put a try/except around the execfile call and have main1.py raise an error to get back to main.py

Post Reply