import random
import asyncio


async def random_number_gen(delay, start, end):
    while True:
        yield random.randint(start, end)
        await asyncio.sleep(delay)


async def main():
    async for i in random_number_gen(1, 0, 100):
        print(i)


try:
    print("Starting to print out random numbers...")
    print("Shut down the application with Ctrl+C")
    asyncio.run(main())
except KeyboardInterrupt:
    print("Closed the main loop..")

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-08-16
  • 2021-07-18
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-26
  • 2021-07-21
  • 2021-10-12
  • 2021-10-12
  • 2021-06-09
  • 2022-12-23
相关资源
相似解决方案