Skip to content

Instantly share code, notes, and snippets.

@miikka

miikka/spinner.py

Last active Nov 3, 2015
Embed
What would you like to do?
#!/usr/bin/env python
# Like sleep(1), but shows a spinner while waiting.
import time
import sys
CHARS = '/-\\|'
def spin(delay):
"""Spin the spinner for `delay` seconds."""
i = 0
deadline = time.time() + delay
while time.time() < deadline:
print "\r" + CHARS[i],
sys.stdout.flush()
i = (i + 1) % len(CHARS)
time.sleep(0.1)
print "\r \r",
if __name__ == '__main__':
spin(int(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment