简体   繁体   English

RuntimeError:超过最大递归深度

[英]RuntimeError: maximum recursion depth exceeded

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: 仅当最后一个re.findall('.*(http://\\S+)'...语句运行时,我re.findall('.*(http://\\S+)'...收到以下错误消息:

 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 call last):
   File "./curl-gui.py", line 105, in urlChange
  text = self.txtUrl.GetValue()
 RuntimeError: maximum recursion depth exceeded

This looks like GUI code? 这看起来像GUI代码吗?

If so I assume that urlChange is called whenever self.txtUrl changes. 如果是这样,我假设self.txtUrl更改时将调用urlChange Therefore when you call self.txtUrl.SetValue(matches[0]) it triggers another call to urlChange , which then repeats and htis the recursion limit. 因此,当您调用self.txtUrl.SetValue(matches[0])它将触发另一个对urlChange调用,该调用将重复并达到递归限制。

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. 为了解决这个问题,您可能应该在调用SetValue之前检查textUrl的值以查看其是否已更改-以防止递归。

Have you tried raising the recrsion limit by using sys.setrecursionlimit()? 您是否尝试过使用sys.setrecursionlimit()提高后退限制? It is by default set to 1000. 默认情况下,它设置为1000。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM