import urllib2
import webbrowser
import time
import sys
URL = "http://nonexisting"
while True:
    try:
        website = urllib2.urlopen(URL, timeout=1)
        if website:
            webbrowser.open_new(URL)
            break
    except KeyboardInterrupt:
        break
    except:
        sys.stdout.write('.')
        time.sleep(1)
I expect this code to write out a dot every second, but instead nothing is happening and when I press CTRL-C I get this output:
^C..........Traceback (most recent call last):
  File "stackoverflow_question.py", line 21, in <module>
    time.sleep(1)
KeyboardInterrupt
So every dot appear after the interrupt. Why is that ? How can I reach the expected result ?
I tried with print statement either with the same result. On OS X and linux too.
 
     
     
    