I have a problem with PhantomJS, which can hang in a loop without reporting any error. I know my code is good because after restarting it normally completes and maybe hangs somewhere later. What I have in mind is maybe something like this: 
i = 0
while i < len(url_list):
    try:
        driver.get(url_list[i])
        # do whatever needs to be done
        i = i+1
        # go on the next one
    except ThisIterationTakesTooLong:
        # try again for this one because the code is definitely good
        continue
Is it even possible to do something like this? Basically, it's a thing in the background that checks how long the loop is running. I know about time.time(), but the problem with that is it won't even measure if it hangs on a command before the counter.
EDIT
After looking at the suggested question, I still have the problem because that signal module doesn't work as it should. 
import signal
signal.alarm(5)
This throws "AttributeError: 'module' object has no attribute 'alarm'"
 So it looks like I can't really use this.
 
    