How can I add a timeout to a charpoly calculation?
For some reason after a bunch of matrix charpoly calculations, charpoly hangs on me. I suppose it's some memory problem, but rather that fix that, I just want to put a timeout on the calculation and then restart it if it hangs.
The problem is I can't use the "alarm" solution given in the answer to this question because sage.matrix.matrix_integer_dense.Matrix_integer_dense.charpoly doesn't catch the KeyboardInterrupt:
sage: M = random_matrix(ZZ,1000,1000) sage: alarm(30) sage: try: ....: P = M.charpoly() ....: except KeyboardInterrupt: ....: print "did not complete!" ....:
What is another approach I could use?