the script gets lost probably because the remote server does not respond anything, or too slow to respond.
you may set a timeout to the socket to avoid this behavior of the process function. at the very beginning of main function
def main():
socket.setdefaulttimeout(3.0)
# process urls
if ......
the above code fragment means that, if getting no response after waiting for 3 seconds, terminate the process and raise a timeout exception. so
try:
process()
except:
pass
will work.