开发者

RuntimeError: maximum recursion depth exceeded

开发者 https://www.devze.com 2023-02-03 15:50 出处:网络
I have the following code which extracts two strings from text by matching different patterns def urlChange(self, event):

I have the following code which extracts two strings from text by matching different patterns

 def urlChange(self, event):
  text = self.txtUrl.GetValue()
  matches = re.findall('GET (\S+).*Host: (\S+).*Cookie: (.+\S)\s*', text, re.DOTALL or re.MULTILINE)
  if matches:
   groups = matches[0]
   self.txtUrl.SetValue(groups[1] + groups[0])
   self.txtCookie.SetValue(groups[2])
  else:
   matches = re.findall('GET (\S+).*Host: (\S+).*', text, re.DOTALL or re.MULTILINE)
   if matches:
    groups = matches[0]
    self.txtUrl.SetValue(groups[1] + groups[0])
    self.txtCookie.Clear()
   else:
    matches = re.findall('.*(http://\S+)', text, re.DOTALL or re.MULTILINE)
    if matches:
     self.txtUrl.SetValue(matches[0]) 
     matches = re.findall('.*Cookie: (.+\S)', text, re.DOTALL or re.MULTILINE)
     if matches:
      self.txtCookie.SetValue(matches[0])

Only when the last re.findall('.*(http://\S+)'... statement runs I get the following error message:

 Traceback (most recent call last):
   File "./curl-gui.py", line 105, in urlChange
  text = self.txtUrl.GetValue()
 RuntimeError: maximum recursion depth exceeded
 Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48, in apport_excepthook
  if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 21, in enabled
  import re
 RuntimeError: maximum recursion depth exceeded while calling a Python object

 Original exception was:
 Traceback (most recent c开发者_高级运维all last):
   File "./curl-gui.py", line 105, in urlChange
  text = self.txtUrl.GetValue()
 RuntimeError: maximum recursion depth exceeded


This looks like GUI code?

If so I assume that urlChange is called whenever self.txtUrl changes. Therefore when you call self.txtUrl.SetValue(matches[0]) it triggers another call to urlChange, which then repeats and htis the recursion limit.

Just a guess - would need more context to be sure, but that's the only possibly recursive behaviour I can see in that code.

To get around this you should probably check the value of textUrl to see if it's changes before calling SetValue - to guard against the recursion.


Have you tried raising the recrsion limit by using sys.setrecursionlimit()? It is by default set to 1000.

0

精彩评论

暂无评论...
验证码 换一张
取 消