On this page
asyncio.EventLoop
Prev: asyncio.Event | Up: asyncio | Next: asyncio.format_call_graph
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.EventLoop
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import EventLoop
Signature & Overview
asyncio.EventLoop(selector=None)
Unix event loop.
Methods & Attributes
EventLoop.add_reader(self, fd, callback, *args)— Add a reader callback.EventLoop.add_signal_handler(self, sig, callback, *args)— Add a handler for a signal. UNIX only.EventLoop.add_writer(self, fd, callback, *args)— Add a writer callback..EventLoop.call_at(self, when, callback, *args, context=None)— Like call_later(), but uses an absolute time.EventLoop.call_exception_handler(self, context)— Call the current event loop's exception handler.EventLoop.call_later(self, delay, callback, *args, context=None)— Arrange for a callback to be called at a given time.EventLoop.call_soon(self, callback, *args, context=None)— Arrange for a callback to be called as soon as possible.EventLoop.call_soon_threadsafe(self, callback, *args, context=None)— Like call_soon(), but thread-safe.EventLoop.close(self)—EventLoop.closemethod/property.EventLoop.connect_accepted_socket(self, protocol_factory, sock, *, ssl=None, ssl_handshake_timeout=None, ssl_shutdown_timeout=None)—EventLoop.connect_accepted_socketmethod/property.EventLoop.connect_read_pipe(self, protocol_factory, pipe)—EventLoop.connect_read_pipemethod/property.EventLoop.connect_write_pipe(self, protocol_factory, pipe)—EventLoop.connect_write_pipemethod/property.EventLoop.create_connection(self, protocol_factory, host=None, port=None, *, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None, ssl_handshake_timeout=None, ssl_shutdown_timeout=None, happy_eyeballs_delay=None, interleave=None, all_errors=False)— Connect to a TCP server.EventLoop.create_datagram_endpoint(self, protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0, reuse_port=None, allow_broadcast=None, sock=None)— Create datagram connection.EventLoop.create_future(self)— Create a Future object attached to the loop.EventLoop.create_server(self, protocol_factory, host=None, port=None, *, family=<AddressFamily.AF_UNSPEC: 0>, flags=<AddressInfo.AI_PASSIVE: 1>, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None, keep_alive=None, ssl_handshake_timeout=None, ssl_shutdown_timeout=None, start_serving=True)— Create a TCP server.EventLoop.create_task(self, coro, **kwargs)— Schedule or begin executing a coroutine object.EventLoop.create_unix_connection(self, protocol_factory, path=None, *, ssl=None, sock=None, server_hostname=None, ssl_handshake_timeout=None, ssl_shutdown_timeout=None)—EventLoop.create_unix_connectionmethod/property.EventLoop.create_unix_server(self, protocol_factory, path=None, *, sock=None, backlog=100, ssl=None, ssl_handshake_timeout=None, ssl_shutdown_timeout=None, start_serving=True, cleanup_socket=True)—EventLoop.create_unix_servermethod/property.EventLoop.default_exception_handler(self, context)— Default exception handler.EventLoop.get_debug(self)—EventLoop.get_debugmethod/property.EventLoop.get_exception_handler(self)— Return an exception handler, or None if the default one is in use.EventLoop.get_task_factory(self)— Return a task factory, or None if the default one is in use.EventLoop.getaddrinfo(self, host, port, *, family=0, type=0, proto=0, flags=0)—EventLoop.getaddrinfomethod/property.EventLoop.getnameinfo(self, sockaddr, flags=0)—EventLoop.getnameinfomethod/property.EventLoop.is_closed(self)— Returns True if the event loop was closed.EventLoop.is_running(self)— Returns True if the event loop is running.EventLoop.remove_reader(self, fd)— Remove a reader callback.EventLoop.remove_signal_handler(self, sig)— Remove a handler for a signal. UNIX only.EventLoop.remove_writer(self, fd)— Remove a writer callback.EventLoop.run_forever(self)— Run until stop() is called.EventLoop.run_in_executor(self, executor, func, *args)—EventLoop.run_in_executormethod/property.EventLoop.run_until_complete(self, future)— Run until the Future is done.EventLoop.sendfile(self, transport, file, offset=0, count=None, *, fallback=True)— Send a file to transport.EventLoop.set_debug(self, enabled)—EventLoop.set_debugmethod/property.EventLoop.set_default_executor(self, executor)—EventLoop.set_default_executormethod/property.EventLoop.set_exception_handler(self, handler)— Set handler as the new event loop exception handler.EventLoop.set_task_factory(self, factory)— Set a task factory that will be used by loop.create_task().EventLoop.shutdown_asyncgens(self)— Shutdown all active asynchronous generators.EventLoop.shutdown_default_executor(self, timeout=None)— Schedule the shutdown of the default executor.
Usage
import asyncio
# Concrete default event loop class on Python 3.14+ / Unix
assert hasattr(asyncio, "new_event_loop")
Gotchas
- Prefer
asyncio.run(): Rarely instantiate event loops directly; useasyncio.Runnerorasyncio.run().
REPL Inspect
from asyncio import EventLoop
help(EventLoop)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/Event Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/format_call_graph Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractEventLoop Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractServer Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/all_tasks Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/as_completed Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Barrier shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseEventLoop shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseProtocol shared tags: #asyncio, #stdlib