I am using Python 3.6 on Win10 x64.
print(10**10**10**10)
Shouldn't this raise an Error? When I run this, it just doesn't print anything, but no error is raised. No OverflowError, no MemoryError, nothing. It has been running for like 10 minutes now. I assume, it is busy calculating? How can I find out, what is actually happening?
It's not finishing the script. (i.e. PyCharm is not printing exit code 0) Why is that?
More generally:
How do I catch a situation like this, if I don't know the magnitude of the calculations involved in advance? I want to stop the script from getting stuck like this "forever" without giving me any sort of error to work with.
.
SOLUTION:
As pointed out by Arthur Spoon below, the OverflowError
is not raised when working with integers. If you want to be able to catch a "too large to compute in reasonable time"-error, it's easiest to just explicitly work only with floats in these circumstances.
At least this works with exponentiation since print(10**10**10.0)
already throws the OverflowError
.
The other option would be using something like the signal
to limit the execution time of that piece of your script.