How can I have a spinner while waiting for socket.accept?
<p>I have a spinner right here:</p>

<pre><code>spinner = itertools.cycle(['-', '/', '|', '\\'])
while True:
    sys.stdout.write(spinner.next())
    sys.stdout.flush()
    sys.stdout.write('\b')
    time.sleep(0.1)
</code></pre>

<p>I'm stuck at my code</p>

<pre><code>server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((target,port))
server.listen(10)
print "Waiting for a client!"
client, addr = server.accept()
</code></pre>

<p>I don't know where or what condition I must use but I know how to implement a spinner. I want my <code>"Waiting for a client"</code> to make it clear for the user that it is waiting. I thought of a spinner.</p>

<p>You should set a timeout before calling <code>accept()</code> in a loop.  See here: <a href="http://stackoverflow.com/questions/7354476/python-socket-object-accept-time-out">python socket object accept time out</a> for details on how, but the idea is to try to accept a new connection for say 0.1 seconds, then bump the spinner, then repeat.</p>

python python-2.7