.. currentmodule:: asyncio
This page lists all low-level asyncio APIs.
Examples
See also the main documentation section about the :ref:`event loop methods <asyncio-event-loop>`.
Lifecycle
True if the event loop is running.
True if the event loop is closed.
await :meth:`loop.shutdown_asyncgens`
Close asynchronous generators.
Debugging
Scheduling Callbacks
Thread/Process Pool
await :meth:`loop.run_in_executor`
Run a CPU-bound or other blocking function in
a :mod:`concurrent.futures` executor.
Tasks and Futures
DNS
Networking and IPC
await :meth:`loop.create_connection`
Open a TCP connection.
await :meth:`loop.create_server`
Create a TCP server.
await :meth:`loop.create_unix_connection`
Open a Unix socket connection.
await :meth:`loop.create_unix_server`
Create a Unix socket server.
await :meth:`loop.connect_accepted_socket`
Wrap a :class:`~socket.socket` into a (transport, protocol)
pair.
await :meth:`loop.create_datagram_endpoint`
Open a datagram (UDP) connection.
await :meth:`loop.sendfile`
Send a file over a transport.
await :meth:`loop.start_tls`
Upgrade an existing connection to TLS.
Sockets
Unix Signals
Subprocesses
Error Handling
Examples
loop.create_connection() to implement
:ref:`an echo-client <asyncio_example_tcp_echo_client_protocol>`.loop.create_connection() to
:ref:`connect a socket <asyncio_example_create_connection>`.All transports implement the following methods:
True if the transport is closing or is closed.
Transports that can receive data (TCP and Unix connections, pipes, etc). Returned from methods like :meth:`loop.create_connection`, :meth:`loop.create_unix_connection`, :meth:`loop.connect_read_pipe`, etc:
Read Transports
True if the transport is receiving.
Transports that can Send data (TCP and Unix connections, pipes, etc). Returned from methods like :meth:`loop.create_connection`, :meth:`loop.create_unix_connection`, :meth:`loop.connect_write_pipe`, etc:
Write Transports
Transports returned by :meth:`loop.create_datagram_endpoint`:
Datagram Transports
Low-level transport abstraction over subprocesses. Returned by :meth:`loop.subprocess_exec` and :meth:`loop.subprocess_shell`:
Subprocess Transports
Protocol classes can implement the following callback methods:
callback :meth:`connection_made() <BaseProtocol.connection_made>`
Called when a connection is made.
callback :meth:`connection_lost() <BaseProtocol.connection_lost>`
Called when the connection is lost or closed.
callback :meth:`pause_writing() <BaseProtocol.pause_writing>`
Called when the transport's buffer goes over the high water mark.
callback :meth:`resume_writing() <BaseProtocol.resume_writing>`
Called when the transport's buffer drains below the low water mark.
Streaming Protocols (TCP, Unix Sockets, Pipes)
callback :meth:`data_received() <Protocol.data_received>`
Called when some data is received.
callback :meth:`eof_received() <Protocol.eof_received>`
Called when an EOF is received.
Buffered Streaming Protocols
callback :meth:`get_buffer() <BufferedProtocol.get_buffer>`
Called to allocate a new receive buffer.
callback :meth:`buffer_updated() <BufferedProtocol.buffer_updated>`
Called when the buffer was updated with the received data.
callback :meth:`eof_received() <BufferedProtocol.eof_received>`
Called when an EOF is received.
Datagram Protocols
callback :meth:`datagram_received()
<DatagramProtocol.datagram_received>`
Called when a datagram is received.
callback :meth:`error_received() <DatagramProtocol.error_received>`
Called when a previous send or receive operation raises an
:class:`OSError`.
Subprocess Protocols
callback :meth:`pipe_data_received()
<SubprocessProtocol.pipe_data_received>`
Called when the child process writes data into its
stdout or stderr pipe.
callback :meth:`pipe_connection_lost()
<SubprocessProtocol.pipe_connection_lost>`
Called when one of the pipes communicating with
the child process is closed.
callback :meth:`process_exited()
<SubprocessProtocol.process_exited>`
Called when the child process has exited.
Policies is a low-level mechanism to alter the behavior of functions like :func:`asyncio.get_event_loop`. See also the main :ref:`policies section <asyncio-policies>` for more details.
Accessing Policies
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。