Detect slow-running loops and abort after a user-defined timeout