I don't get why sys.exit(1) doesn't exit the while loop in the follow case

chad cdalten at gmail.com
Mon Oct 4 22:38:45 EDT 2010


Given the following..

#!/usr/bin/python

import urllib2
import sys
import time

while 1:
    try:
        con = urllib2.urlopen("http://www.google.com")
        data = con.read()
        print "connected"
        #The loop doesn't exit if I use sys.exit(1)
        break
    except:
        time.sleep(2)


If I would replace 'break' with 'sys.exit(1)', the while loop will
keep printing connected every 2 seconds? Why I this? I thought exit
meant exit.



More information about the Python-list mailing list