2011-01-12 123 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.

相關問題