MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / spin

Function spin

19-concurrency/spinner_async.py:11–20  ·  view source on GitHub ↗
(msg: str)

Source from the content-addressed store, hash-verified

9import itertools
10
11async def spin(msg: str) -> None: # <1>
12 for char in itertools.cycle(r'\|/-'):
13 status = f'\r{char} {msg}'
14 print(status, flush=True, end='')
15 try:
16 await asyncio.sleep(.1) # <2>
17 except asyncio.CancelledError: # <3>
18 break
19 blanks = ' ' * len(status)
20 print(f'\r{blanks}\r', end='')
21
22async def slow() -> int:
23 await asyncio.sleep(3) # <4>

Callers 1

supervisorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected