Skip to content

Instantly share code, notes, and snippets.

@miikka
Last active November 3, 2015 14:57
Show Gist options
  • Save miikka/ef51606feb0ed0373861 to your computer and use it in GitHub Desktop.
Save miikka/ef51606feb0ed0373861 to your computer and use it in GitHub Desktop.
#!/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