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

Von vontio at gmail.com
Mon Oct 4 23:13:53 EDT 2010


Try to use sys.exit(0)
Maybe you should print out the error in your except block.


2010/10/5, chad <cdalten at gmail.com>:
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list