Progress dots with a Thread in Python
Question: I am trying to create a thread in Python that will poll some server as long as
it won't get proper answer (HTTP GET). In order to provide convenient text UI
I want to print progress dots. Another dot with every connection attempt until
it finish (or just another dot with every another second of waiting).

I have found something like this:
<http://code.activestate.com/recipes/535141-console-progress-dots-using-
threads-and-a-context-/>

In this example we have context manager:

    
    
    with Ticker("A test"):
        time.sleep(10)
    

I am not sure if I understand that properly. I would like to do something
like:

    
    
    with Ticker("A test: "):      
        result = -1
        while result != 0:
            result = poll_server()
        print "Finished."
    

But this does not work. Any ideas?

Cheers


Answer: Python buffers your output, so many dots will appear at once. One way around
that is to `import sys` and use that: whenever you want to print a dot, say:

    
    
    sys.stdout.write(".")
    sys.stdout.flush()
    

The flush makes the dot appear immediately.

