Yesterday, 10:02 AM
Hi,
On line 12 below, I get a warning msg from pycharm stating "Coroutine 'create_task' is not awaited".
If I do modify it with
How should I improve the code?
TIA
On line 12 below, I get a warning msg from pycharm stating "Coroutine 'create_task' is not awaited".
If I do modify it with
await asyncio.create_task(getTemperatures(5))then, the code will not proceed to the next line.
How should I improve the code?
TIA
import asyncio from datetime import datetime async def getTemperatures(t): while True: now = datetime.now() print(f'Displaying every 5 secs. {now:%S}') await asyncio.sleep(t) async def main(): asyncio.create_task(getTemperatures(5)) # await asyncio.create_task(getTemperatures(5)) while True: print('Clocking every second') await asyncio.sleep(1) def run(): try: asyncio.run(main()) except KeyboardInterrupt as err: print(f'kb interrupted {err}') if __name__ == "__main__": run()