import asyncio import itertools import sys async def spin(msg): write, flush = sys.stdout.write, sys.stdout.flush for char in itertools.cycle('|/-\\'): status = f"{char} {msg}" write(status) flush() write('\x08' * len(status)) # backspace out the line try: await asyncio.sleep(.1) except asyncio.CancelledError: break write(' ' * len(status) + '\x08' * len(status)) async def slow_function(): await asyncio.sleep(3) return 42 async def supervisor(): spinner = loop.create_task(spin('Thinking!')) print('Spinner Object:', spinner) result = await slow_function() spinner.cancel() return result if __name__ == '__main__': try: loop = asyncio.get_event_loop() # returns a Task object, not the result objects themselves. You have to access the Task result # to see the output result = loop.run_until_complete(supervisor()) except Exception as e: pass finally: loop.close()