I need to open a port to the serial device but if it has not been opened or there is an exception it must continuously try to open the door until it opens. Python 2.7.3 after a while I get this error:
“RuntimeError: maximum recursion depth exceeded while calling a Python
object”
Can you help me?
My code:
def opendisplay():
try:
lcd = serial.Serial(
port='/dev/display',
baudrate=9600,
timeout=0,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
except Exception, e:
print "Error! can't connect to display Lcd check USB-Serial \n" + str(e)
opendisplay()
return lcd
dsp=opendisplay()
As Martin/Shadow says, loop instead of recurse:
If you want to only keep trying for a minute, you can use
for _ in range(60)instead