Python Forum
help RuntimeError: no running event loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help RuntimeError: no running event loop
#5
What is this supposed to do?
tasks = (asyncio.create_task([row[0] for row in csv.reader(d)]))
According to the documentation, the first argument to asyncio.create_task() is the coroutine.

Are you trying to do something like this where the csv reader provides arguments for the coroutine?
import asyncio

# Emulate (very loosely) a csv reader
csvReader = [[i] for i in range(1, 10)]

async def coroutine(value=3):
    await asyncio.sleep(1)
    return value**2


async def main():
    tasks = (asyncio.create_task(coroutine(row[0])) for row in csvReader)
    results = await asyncio.gather(*tasks, return_exceptions=True)
    print(results)

asyncio.run(main())
Reply


Messages In This Thread
RE: help RuntimeError: no running event loop - by deanhystad - Oct-18-2022, 09:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A question about 'Event loop is closed' fc5igm 2 2,381 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  bleak library RuntimeError: This event loop is already running alice93 3 4,269 Sep-30-2021, 08:06 AM
Last Post: alice93
  loop running indefinitely shantanu97 6 2,713 Sep-29-2021, 08:03 PM
Last Post: deanhystad
  Running A Loop Until You See A Particular Result knight2000 6 32,087 Sep-04-2021, 08:55 AM
Last Post: knight2000
  Running loop at specific frequency mdsousa 3 6,153 Apr-21-2021, 11:22 AM
Last Post: jefsummers
  RuntimeError: generator raised StopIteration quest 1 5,906 Mar-28-2021, 08:11 PM
Last Post: quest
  RuntimeError: This event loop is already running newbie2019 2 7,049 Sep-30-2020, 06:59 PM
Last Post: forest44
  RuntimeError: Optimal parameters not found: Number of calls to function has reached m bntayfur 0 6,249 Aug-05-2020, 04:41 PM
Last Post: bntayfur
  Running function from parent module which has a loop in it. ta2909i 1 2,749 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  RuntimeError: can't open file Hadad 2 5,475 Aug-27-2019, 04:23 PM
Last Post: Hadad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020