
Any process that runs autonomously for a considerable period needs a watchdog.
I have Excel VBA analysing web pages' contents via Selenium. At various points in the code a UDP message is sent to a VB.Net watchdog application in the same PC. The message indicates what is being processed at that instant.
If the watchdog gets a message with the same state/data information several times in succession then it assumes the current page's HTML has triggered some unexpected loop.
If the watchdog doesn't get a message within the allocated time then it logs the last message's state/data.
In both cases it kills the Excel instance. It then restarts Excel to continue with the next page - having marked the failing page for a retry later.
If the Excel run completes then the watchdog puts the PC into hibernation mode - and the log has recorded any anomalies..
There are obviously other OS related failure modes that the watchdog wouldn't catch. In several years it has never been hit with a situation that the above didn't circumvent automatically.