File tree Expand file tree Collapse file tree 2 files changed +5
-14
lines changed
Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Original file line number Diff line number Diff line change 99# BEGIN SPINNER_ASYNCIO
1010import asyncio
1111import itertools
12- import sys
1312
1413
1514async def spin (msg ): # <1>
16- write , flush = sys .stdout .write , sys .stdout .flush
1715 for char in itertools .cycle ('|/-\\ ' ):
1816 status = char + ' ' + msg
19- write (status )
20- flush ()
21- write ('\x08 ' * len (status ))
17+ print (status , flush = True , end = '\r ' )
2218 try :
2319 await asyncio .sleep (.1 ) # <2>
2420 except asyncio .CancelledError : # <3>
2521 break
26- write (' ' * len (status ) + ' \x08 ' * len ( status ) )
22+ print (' ' * len (status ), end = ' \r ' )
2723
2824
2925async def slow_function (): # <4>
Original file line number Diff line number Diff line change 1010import threading
1111import itertools
1212import time
13- import sys
1413
1514
16- def spin (msg , done ): # <2>
17- write , flush = sys .stdout .write , sys .stdout .flush
15+ def spin (msg , done ): # <1>
1816 for char in itertools .cycle ('|/-\\ ' ): # <3>
1917 status = char + ' ' + msg
20- write (status )
21- flush ()
22- write ('\x08 ' * len (status )) # <4>
18+ print (status , flush = True , end = '\r ' )
2319 if done .wait (.1 ): # <5>
2420 break
25- write (' ' * len (status ) + '\x08 ' * len (status )) # <6>
26-
21+ print (' ' * len (status ), end = '\r ' )
2722
2823def slow_function (): # <7>
2924 # pretend waiting a long time for I/O
You can’t perform that action at this time.
0 commit comments