Created
May 29, 2022 06:52
-
-
Save justxor/256e64eb335ff2c41d6e783d1f982220 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
import itertools | |
import sys | |
import time | |
def spinner(seconds): | |
"""Show an animated spinner while we sleep.""" | |
symbols = itertools.cycle('-|/') | |
tend = time.time() + seconds | |
while time.time() < tend: | |
# 'r' is carriage return: return cursor to the start of the line. | |
sys.stdout.write('\rPlease wait... ' + next(symbols)) # no newline | |
sys.stdout.flush() | |
time.sleep(0.1) | |
print() # newline | |
if __name__ == "__main__": | |
spinner(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment