Last active
November 3, 2015 14:57
-
-
Save miikka/ef51606feb0ed0373861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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