Skip to content

Instantly share code, notes, and snippets.

@justxor
Created May 29, 2022 06:52
Show Gist options
  • Save justxor/256e64eb335ff2c41d6e783d1f982220 to your computer and use it in GitHub Desktop.
Save justxor/256e64eb335ff2c41d6e783d1f982220 to your computer and use it in GitHub Desktop.
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