1
我在一個特別大的輸入集上運行我的Python longest common subsequence算法,將結果的LCS長度存儲在二維numpy數組中。我注意到隨着時間的推移它正在減速。大約三分之一的時間,它慢慢爬行,然後崩潰,打印神祕的錯誤信息「pnc =:N」,之後沒有換行(我的程序在停止之前再打印一行輸出)。在這一點上它似乎也釋放了大量的分配內存。有誰知道這意味着什麼?Python:Odd「pnc =:N」error message
編輯:崩潰的代碼的部分是:
#m and n are both around 12,000
lengths = np.empty((m+1, n+1), dtype=np.uint)
lengths[0,:] = 0
lengths[1:,0] = 0
if m > 0 and n > 0:
for i in xrange(1, m + 1):
for j in xrange(1, n + 1):
#eqTest is a function comparing two sequence elements, like cmp
eq = eqTest(a[i-1], b[j-1])
if eq:
lengths[i,j] = lengths[i-1,j-1] + 1
elif lengths[i-1,j] >= lengths[i,j-1]:
lengths[i,j] = lengths[i-1,j]
else:
lengths[i,j] = lengths[i,j-1]
我不知道是什麼原因導致它慢下來或使用更多的資源隨着時間的推移,由於整個LCS長度數組在分配開始然後填充。我使用的是平等的測試是很難形容,因爲這部分是用C寫的,但它是有效的:
def eqTest(l1, l2):
words1 = l1.split()
words2 = l2.split()
if len(words1) == len(words2):
for i in xrange(len(words1)):
#MATCHERS is a list of around 10 compiled regular expressions
for m in MATCHERS:
if m.match(s1) is not None and m.match(s2) is not None:
break
else:
result = False
break
else:
result = True
else:
result = False
return result
我的代碼是幾千行,但我加入了我認爲是相對的部分。順便說一下,我使用的是Windows 7。在檢查我的系統監視器時,很明顯我的程序正在泄漏內存,可能是C代碼。我主要對錯誤信息感到好奇。你能爲我解開這個嗎? – dpitch40
@ dpitch40這不是一個標準的python錯誤。我不知道你在使用什麼第三方模塊。嘗試使用源代碼,以及您正在使用的其他模塊的源代碼來查看是否有任何問題。 – Marcin