2011-01-12 88 views
0

我有下面的代码,通过匹配不同的图案RuntimeError:最大递归深度超过

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]) 

提取从文本两个字符串只有当最后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 
+4

我什么都不知道,但它看起来像问题是'self.txtUrl.GetValue()`行。 “GetValue”有什么作用? – Kobi 2011-01-12 12:06:06

回答

2

这看起来像GUI代码?

如果是这样,我假设urlChange被调用,每当self.txtUrl变化。因此,当您拨打self.txtUrl.SetValue(matches[0])时,会触发另一个致电urlChange的呼叫,然后重复并达到递归限制。

只是猜测 - 将需要更多的上下文来确定,但这是我可以在代码中看到的唯一可能的递归行为。

为了解决这个问题,你应该在调用SetValue之前检查textUrl的值是否变化 - 以防止递归。

+0

我测试过了 - 修改事件处理程序内部的文本没有问题,它不会触发无限递归。但是我不能重现这个问题。这可能与输入文本本身有关。 – jackhab 2011-01-27 09:26:17

+0

看起来您可能会在某些值上出现一些奇怪的行为 - 因为您在文本字段中匹配了值,然后用其他值替换,但很难确切地看到可能触发它的值。 – 2011-01-28 12:13:50

1

你有没有尝试通过使用sys.setrecursionlimit()提高recrsion限制?它是默认设置为1000.

相关问题