File tree 2 files changed +5
-14
lines changed
2 files changed +5
-14
lines changed Original file line number Diff line number Diff line change 9
9
# BEGIN SPINNER_ASYNCIO
10
10
import asyncio
11
11
import itertools
12
- import sys
13
12
14
13
15
14
async def spin (msg ): # <1>
16
- write , flush = sys .stdout .write , sys .stdout .flush
17
15
for char in itertools .cycle ('|/-\\ ' ):
18
16
status = char + ' ' + msg
19
- write (status )
20
- flush ()
21
- write ('\x08 ' * len (status ))
17
+ print (status , flush = True , end = '\r ' )
22
18
try :
23
19
await asyncio .sleep (.1 ) # <2>
24
20
except asyncio .CancelledError : # <3>
25
21
break
26
- write (' ' * len (status ) + ' \x08 ' * len ( status ) )
22
+ print (' ' * len (status ), end = ' \r ' )
27
23
28
24
29
25
async def slow_function (): # <4>
Original file line number Diff line number Diff line change 10
10
import threading
11
11
import itertools
12
12
import time
13
- import sys
14
13
15
14
16
- def spin (msg , done ): # <2>
17
- write , flush = sys .stdout .write , sys .stdout .flush
15
+ def spin (msg , done ): # <1>
18
16
for char in itertools .cycle ('|/-\\ ' ): # <3>
19
17
status = char + ' ' + msg
20
- write (status )
21
- flush ()
22
- write ('\x08 ' * len (status )) # <4>
18
+ print (status , flush = True , end = '\r ' )
23
19
if done .wait (.1 ): # <5>
24
20
break
25
- write (' ' * len (status ) + '\x08 ' * len (status )) # <6>
26
-
21
+ print (' ' * len (status ), end = '\r ' )
27
22
28
23
def slow_function (): # <7>
29
24
# pretend waiting a long time for I/O
You can’t perform that action at this time.
0 commit comments