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 –