Created
May 28, 2019 17:59
-
-
Save GreatBahram/1c551f35a5fd988e22640a97606148ca to your computer and use it in GitHub Desktop.
simple spinner
This file contains 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 threading | |
import time | |
class Signal: | |
stop = False | |
def spin(msg, signal): | |
write, flush = sys.stdout.write, sys.stdout.flush | |
for char in itertools.cycle('|/-\\'): | |
status = char + ' ' + msg | |
write(status) | |
flush() | |
write('\b' * len(status)) | |
time.sleep(0.1) | |
if signal.stop: | |
break | |
write(' ' * len(status) + '\b' * len(status)) | |
def main(): | |
signal = Signal() | |
spinner = threading.Thread(target=spin, args=('Hi', signal)) | |
spinner.start() | |
time.sleep(3) | |
signal.stop = True | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment