python-igraph icon indicating copy to clipboard operation
python-igraph copied to clipboard

incorrect handling of igraph warnings if the user turns them into an exception

Open ntamas opened this issue 10 years ago • 2 comments

From Stack Overflow. A short code fragment to reproduce:

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"

This will print:

MemoryError: Error at src/attributes.c:284: not enough memory to allocate attribute hashes, Out of memory

The problem is that the C core of igraph never anticipates that some warnings are turned into errors, therefore it does not bail out from igraph_degree_sequence_game at the point where the warning was raised.

ntamas avatar Jul 21 '15 13:07 ntamas

It seems like this cannot be solved without re-writing nearly every function handler in the C core, which I'd rather not attempt before the 0.8 release.

Basically, what we need to do in the C core is that we need to check PyErr_Occurred() after every igraph function call in case a warning generated by igraph was turned into an error. If this happens, we need to do regular cleanup instead of continuing with the C glue code.

ntamas avatar Jan 30 '20 10:01 ntamas

Another option would be to change the C core such that warning handlers could return a value indicating that the warning has been converted into an error by the higher level layer, at which point the C core could treat the warning as if it was an exception.

ntamas avatar Jan 30 '20 10:01 ntamas