test for absence of infinite loop
steve+comp.lang.python at pearwood.info
Tue Jul 17 08:30:41 EDT 2018
On Tue, 17 Jul 2018 10:10:49 +0100, Robin Becker wrote:
> A user reported an infinite loop in reportlab. I determined a possible
> cause and fix and would like to test for absence of the loop. Is there
> any way to check for presence/absence of an infinite loop in python? I
> imagine we could do something like call an external process and see if
> it takes too long, but that seems a bit flaky.
In general, no, it is impossible to detect infinite loops.
That's not to say that either human readers or the compiler can't detect
*some* infinite loops ahead of time:
# obviously an infinite loop
and then there's this:
but Python's compiler isn't capable of anything like that.
The way I sometimes deal with that sort of thing is to re-write selected
# condition may never become False
to something like this:
for counter in range(1000):
if not condition: break
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list