1
我運行的代碼手柄/掛鉤RuntimeWarnings
testgraph = igraph.Graph.Degree_Sequence(degseq,method = "vl")
有時拋出的警告
RuntimeWarning: Cannot shuffle graph, maybe there is only a single one? at gengraph_graph_molloy_hash.cpp:332
我想抓住這個警告,所以我可以停止工作度數序列只有一個圖。
我試圖
degseq = [1,2,2,3]
try:
testgraph = igraph.Graph.Degree_Sequence(degseq,method = "vl")
except RuntimeWarning:
print degseq
else:
print "go on"
返回警告,然後 「繼續」。
我試圖警告與
warnings.simplefilter('error', 'Cannot shuffle graph')
degseq = [1,2,2,3]
try:
testgraph = igraph.Graph.Degree_Sequence(degseq,method = "vl")
except RuntimeWarning:
print degseq
else:
print "go on"
升級到異常等等,而現在很奇怪發生!它返回
testgraph = igraph.Graph.Degree_Sequence(degseq,method = "vl")
MemoryError: Error at src/attributes.c:284: not enough memory to allocate attribute hashes, Out of memory
如何使python捕獲RuntimeWarning?爲什麼當我將警告升級爲異常時會發生新的異常?
我已經添加了一個bug報告給python-igraph關於MemoryError的問題跟蹤器:https://github.com/igraph/python-igraph/issues/38 –