---
source: https://iinventedlight.com/library/notes/python-asyncio-eventloop.md
title: "Python asyncio event loop: run tasks, callbacks, and I/O"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Event loop; CPython, Event loop documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-asyncio-eventloop"
tags: [python, asyncio, event-loop, coroutines, run]
client: Librarian
sources:
  - id: S1
    title: "Event loop"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/asyncio-eventloop.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "Event loop documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/asyncio-eventloop.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python asyncio event loop: run tasks, callbacks, and I/O
**Answer:** The event loop is the core of every asyncio application, running asynchronous tasks and callbacks, network I/O operations, and subprocesses.

## Who should call loop methods

Application developers should typically stay with high-level asyncio functions such as asyncio.run(), and only rarely reference the loop object or invoke its methods directly.

The page is aimed mostly at authors of lower-level code, libraries, and frameworks who want finer control over event-loop behavior.

get_running_loop() raises RuntimeError when no loop is running, and it may be called only from a coroutine or a callback.

get_running_loop() was added in version 3.7.

From a coroutine or a callback, get_event_loop() returns the running loop. When no loop is running, it may return whatever the current policy's get_event_loop() provides.

Because that behavior is complex, especially with a custom policy, the docs prefer get_running_loop() inside coroutines and callbacks.

Since version 3.14, get_event_loop() raises RuntimeError when there is no current loop.

A custom event loop policy can change how get_event_loop(), set_event_loop(), and new_event_loop() behave.

Consider asyncio.run() instead of using lower-level functions to manually create and close an event loop.

## Running and closing the loop

If the argument is a coroutine object it is implicitly scheduled to run as a Task.

run_until_complete() returns a Future's result or raises its exception.

run_forever() keeps the loop going until stop() is called.

If stop() happens while run_forever() is already running, the loop finishes the current batch of callbacks and then returns.

close() must be called when the loop is not running. Pending callbacks are discarded.

close() clears queues and shuts down the executor without waiting for that executor to finish.

## See also

- [python-asyncio-basics](https://iinventedlight.com/library/notes/python-asyncio-basics/)
- [python-asyncio-timeouts](https://iinventedlight.com/library/notes/python-asyncio-timeouts/)
- [python-asyncio-taskgroup](https://iinventedlight.com/library/notes/python-asyncio-taskgroup/)

## Claims

- id: C1
  claim: Higher-level asyncio.run() is what most application code should call.
  source: S1
  evidence: "Application developers should typically use the high-level asyncio functions"

- id: C2
  claim: get_running_loop() cannot be used outside a coroutine or callback.
  source: S2
  evidence: "This function can only be called from a coroutine or a callback."

- id: C3
  claim: run_forever() continues until stop() is invoked.
  source: S1
  evidence: "Run the event loop until stop() is called."

## Sources

- [S1] Event loop. Python Software Foundation. https://docs.python.org/3/library/asyncio-eventloop.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] Event loop documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/asyncio-eventloop.rst . License: PSF License Version 2. Accessed 2026-11-26.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Event loop; CPython, Event loop documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
