LYRENTH
AgentsDocsPricingBenchmarksIndex statsAboutBlogFor site ownersStatusContact
Documentation answers

How do I run a coroutine, and what do I need before I can?

Point it at the documentation that should hold the answer, and ask. It reads the pages and writes the answer with the section heading behind every line.

What came back

The answer, as it printed.

Every claim names the page and the heading it came from, which is what makes an answer worth pasting into a pull request.

answers · lyrenth-agents
$uvx lyrenth-agents answers -q "How do I run a coroutine, and what do I need before I can?" https://docs.python.org/3/library/asyncio-task.html https://docs.python.org/3/library/asyncio-runner.html
recipe answers: Documentation answersread[1] Coroutines and tasks 16,048 tokens https://docs.python.org/3/library/asyncio-task.htmlread[2] Runners 2,219 tokens https://docs.python.org/3/library/asyncio-runner.htmlcontext 18,267 tokens from 2 sources (raw HTML would be 53,372)
How do I run a coroutine, and what do I need before I can?

To run a coroutine, you can use one of these mechanisms:
- Use asyncio.run(coro) to execute the coroutine in a new event loop and return its result. The argument can be any awaitable object. This function should be used as the main entry point for asyncio programs and cannot be called when another event loop is running in the same thread [2], "Running an asyncio Program".
- Await the coroutine from within another coroutine using the await keyword [1], "Coroutines".
- Use asyncio.create_task(coro) to schedule the coroutine as a Task for concurrent execution within an event loop. You must have a running event loop in the current thread, or a RuntimeError is raised [1], "Creating tasks".
- Use asyncio.TaskGroup (Python 3.11+) as an async context manager to create and manage multiple tasks [1], "Task groups".

Before you can run a coroutine:
- You need an event loop running in the current thread. asyncio.run() and asyncio.Runner() will create and manage the event loop for you. If you use create_task(), you must already be inside a running event loop (e.g., inside another coroutine) [1], "Creating tasks"; [2], "Running an asyncio Program".
- If you use asyncio.run(), you cannot already have another event loop running in the same thread [2], "Running an asyncio Program".

Example using asyncio.run():
```python
import asyncio

async def main():
    print('hello')
    await asyncio.sleep(1)
    print('world')

asyncio.run(main())
```
[1], "Coroutines"; [2], "Running an asyncio Program"

Example using create_task() inside a coroutine:
```python
import asyncio

async def say_after(delay, what):
    await asyncio.sleep(delay)
    print(what)

async def main():
    task1 = asyncio.create_task(say_after(1, 'hello'))
    task2 = asyncio.create_task(say_after(2, 'world'))
    await task1
    await task2

asyncio.run(main())
```
[1], "Coroutines"

Summary:
- Use asyncio.run() or asyncio.Runner().run() for top-level entry.
- Use await or create_task() inside a running event loop.
- You need a running event loop, which asyncio.run() provides, or you must already be inside one for create_task().
[1], "Coroutines", "Creating tasks"; [2], "Running an asyncio Program", "Runner context manager"

Sources
  [1] Coroutines and tasks  https://docs.python.org/3/library/asyncio-task.html
  [2] Runners  https://docs.python.org/3/library/asyncio-runner.html
Captured 2026-09-21. The command, the pages, and every line it printed.
The pages it read
  1. [1]Coroutines and taskshttps://docs.python.org/3/library/asyncio-task.html
  2. [2]Runnershttps://docs.python.org/3/library/asyncio-runner.html
2pages read
18,267tokens of text
53,372tokens as raw HTML
What you give

The documentation pages that should hold the answer, with the most likely page first.

The pages in this run
  • https://docs.python.org/3/library/asyncio-task.html
  • https://docs.python.org/3/library/asyncio-runner.html
What you get

The answer in plain words with the page and the section heading it came from, and a plain 'the docs given do not say' when the pages do not answer it.

By hand this is the site's own search box, six tabs, and a paragraph you are not certain is current.

Run it

The command that produced all of this.

Paste it as it is and watch it work, then swap in your own pages. With your Lyrenth key set, it prints the finished prompt and its numbered sources, ready for whichever assistant you already use. Point it at an OpenAI-compatible endpoint and it answers on its own, the way the run above did.

uvx lyrenth-agents answers -q "How do I run a coroutine, and what do I need before I can?" https://docs.python.org/3/library/asyncio-task.html https://docs.python.org/3/library/asyncio-runner.html