Python Forum
How to add coroutine to a running event loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add coroutine to a running event loop?
#1
Python 3.5

Initially, I launched several coroutine in ordered stages (which in the coroutine contain their tasks):
async def _create_workers(self):
    scheme = get_scheme()
    for stage in scheme.get_next_stage():
        await asyncio.gather(*stage)

loop = asyncio.get_event_loop()
loop.run_until_complete(self._create_workers())
But in the process of work, it became known that one of the coroutine doesn't have time to done with its tasks, and I want to add copies of it. I analyze the load from one of the coroutine ('main'- coroutine), which adds data for processing. But if I create new task I have to wait for the new coroutine to complete:
new_task = asyncio.ensure_future(slow_coro())
await new_task
But I don’t want to stop the execution flow 'main'- coroutine for waiting! I just want to add it to the current stage and so that the processing stage will finish only when the new coroutine is also completed.

How I can do it?
Reply


Messages In This Thread
How to add coroutine to a running event loop? - by AlekseyPython - Mar-21-2019, 02:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Coroutine was never awaited error bucki 1 665 Sep-23-2023, 08:17 PM
Last Post: deanhystad
  help RuntimeError: no running event loop marpaslight 5 3,760 Oct-18-2022, 10:04 PM
Last Post: marpaslight
  A question about 'Event loop is closed' fc5igm 2 2,232 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  bleak library RuntimeError: This event loop is already running alice93 3 4,117 Sep-30-2021, 08:06 AM
Last Post: alice93
  loop running indefinitely shantanu97 6 2,601 Sep-29-2021, 08:03 PM
Last Post: deanhystad
  Running A Loop Until You See A Particular Result knight2000 6 31,726 Sep-04-2021, 08:55 AM
Last Post: knight2000
  Running loop at specific frequency mdsousa 3 5,961 Apr-21-2021, 11:22 AM
Last Post: jefsummers
  RuntimeError: This event loop is already running newbie2019 2 6,964 Sep-30-2020, 06:59 PM
Last Post: forest44
  Running function from parent module which has a loop in it. ta2909i 1 2,698 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  How to get coroutine from a task, and an object from a coroutine? AlekseyPython 2 4,431 Mar-23-2019, 01:41 PM
Last Post: AlekseyPython

Forum Jump:

User Panel Messages

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