We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6de94c1 commit a58ecf6Copy full SHA for a58ecf6
2 files changed
18-asyncio-py3.7/spinner_asyncio.py
@@ -9,21 +9,17 @@
9
# BEGIN SPINNER_ASYNCIO
10
import asyncio
11
import itertools
12
-import sys
13
14
15
async def spin(msg): # <1>
16
- write, flush = sys.stdout.write, sys.stdout.flush
17
for char in itertools.cycle('|/-\\'):
18
status = char + ' ' + msg
19
- write(status)
20
- flush()
21
- write('\x08' * len(status))
+ print(status, flush=True, end='\r')
22
try:
23
await asyncio.sleep(.1) # <2>
24
except asyncio.CancelledError: # <3>
25
break
26
- write(' ' * len(status) + '\x08' * len(status))
+ print(' ' * len(status), end='\r')
27
28
29
async def slow_function(): # <4>
18-asyncio-py3.7/spinner_thread.py
@@ -10,20 +10,15 @@
import threading
import time
-def spin(msg, done): # <2>
+def spin(msg, done): # <1>
for char in itertools.cycle('|/-\\'): # <3>
- write('\x08' * len(status)) # <4>
if done.wait(.1): # <5>
- write(' ' * len(status) + '\x08' * len(status)) # <6>
-
def slow_function(): # <7>
# pretend waiting a long time for I/O
0 commit comments