I don't get why sys.exit(1) doesn't exit the while loop in the follow case
Terry Reedy
tjreedy at udel.edu
Mon Oct 4 23:02:18 EDT 2010
On 10/4/2010 10:38 PM, chad wrote:
> 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)
Guess how sys.exit is implemented (or check the fine library manual
chapter on the sys module, .exit entry, 2nd sentence).
> break
> except:
and guess what this does, and why bare excepts are not recommended
unless you mean what you say...
> time.sleep(2)
--
Terry Jan Reedy
More information about the Python-list
mailing list