低级 API 索引 ¶
本页列出了所有低级 asyncio API。
获得事件循环 ¶
|
The preferred function to get the running event loop. |
|
|
Get an event loop instance (running or current via the current policy). |
|
|
Set the event loop as current via the current policy. |
|
|
创建新的事件循环。 |
范例
事件循环方法 ¶
See also the main documentation section about the 事件循环方法 .
Lifecycle
|
Run a Future/Task/awaitable until complete. |
|
|
Run the event loop forever. |
|
|
停止事件循环。 |
|
|
关闭事件循环。 |
|
|
返回
|
|
|
返回
|
|
|
Close asynchronous generators. |
调试
|
Enable or disable the debug mode. |
|
|
Get the current debug mode. |
Scheduling Callbacks
|
Invoke a callback soon. |
|
|
A thread-safe variant of
|
|
|
Invoke a callback after the given time. |
|
|
Invoke a callback at the given time. |
线程/进程池
|
|
Run a CPU-bound or other blocking function in a
|
|
Set the default executor for
|
任务和未来
|
创建
|
|
|
Schedule coroutine as a
|
|
|
Set a factory used by
|
|
|
Get the factory
|
DNS
|
|
Asynchronous version of
|
|
|
Asynchronous version of
|
网络和 IPC (进程间通信)
|
|
Open a TCP connection. |
|
|
Create a TCP server. |
|
Open a Unix socket connection. |
|
|
Create a Unix socket server. |
|
|
包裹
|
|
|
Open a datagram (UDP) connection. |
|
|
|
Send a file over a transport. |
|
|
Upgrade an existing connection to TLS. |
|
|
Wrap a read end of a pipe into a
|
|
Wrap a write end of a pipe into a
|
套接字
|
|
Receive data from the
|
|
|
Receive data from the
|
|
|
Receive a datagram from the
|
|
Receive a datagram from the
|
|
|
|
Send data to the
|
|
|
Send a datagram via the
|
|
|
连接
|
|
|
Accept a
|
|
|
Send a file over the
|
|
Start watching a file descriptor for read availability. |
|
|
Stop watching a file descriptor for read availability. |
|
|
Start watching a file descriptor for write availability. |
|
|
Stop watching a file descriptor for write availability. |
Unix 信号
|
Add a handler for a
|
|
|
Remove a handler for a
|
子进程
|
Spawn a subprocess. |
|
|
Spawn a subprocess from a shell command. |
错误处理
|
Call the exception handler. |
|
|
Set a new exception handler. |
|
|
Get the current exception handler. |
|
|
The default exception handler implementation. |
范例
-
使用
loop.create_connection()以实现 an echo-client . -
使用
loop.create_connection()to connect a socket .
传输 ¶
All transports implement the following methods:
|
Close the transport. |
|
|
返回
|
|
|
Request for information about the transport. |
|
|
Set a new protocol. |
|
|
Return the current protocol. |
Transports that can receive data (TCP and Unix connections, pipes, etc). Returned from methods like
loop.create_connection()
,
loop.create_unix_connection()
,
loop.connect_read_pipe()
, etc:
Read Transports
|
返回
|
|
|
Pause receiving. |
|
|
Resume receiving. |
Transports that can Send data (TCP and Unix connections, pipes, etc). Returned from methods like
loop.create_connection()
,
loop.create_unix_connection()
,
loop.connect_write_pipe()
, etc:
Write Transports
|
Write data to the transport. |
|
|
Write buffers to the transport. |
|
|
返回
|
|
|
Close and send EOF after flushing buffered data. |
|
|
Close the transport immediately. |
|
|
Return the current size of the output buffer. |
|
|
Return high and low water marks for write flow control. |
|
|
Set new high and low water marks for write flow control. |
Transports returned by
loop.create_datagram_endpoint()
:
数据报传输
|
Send data to the remote peer. |
|
|
Close the transport immediately. |
Low-level transport abstraction over subprocesses. Returned by
loop.subprocess_exec()
and
loop.subprocess_shell()
:
子进程传输
|
Return the subprocess process id. |
|
|
Return the transport for the requested communication pipe ( stdin , stdout ,或 stderr ). |
|
|
Return the subprocess return code. |
|
|
杀除子进程。 |
|
|
Send a signal to the subprocess. |
|
|
停止子进程。 |
|
|
Kill the subprocess and close all pipes. |
协议 ¶
Protocol classes can implement the following callback methods :
|
|
Called when a connection is made. |
|
|
Called when the connection is lost or closed. |
|
|
Called when the transport’s buffer goes over the high water mark. |
|
|
Called when the transport’s buffer drains below the low water mark. |
Streaming Protocols (TCP, Unix Sockets, Pipes)
|
|
Called when some data is received. |
|
|
Called when an EOF is received. |
缓冲流协议
|
|
Called to allocate a new receive buffer. |
|
|
Called when the buffer was updated with the received data. |
|
|
Called when an EOF is received. |
数据报协议
|
|
Called when a datagram is received. |
|
|
Called when a previous send or receive operation raises an
|
子进程协议
|
|
Called when the child process writes data into its stdout or stderr pipe. |
|
|
Called when one of the pipes communicating with the child process is closed. |
|
|
Called when the child process has exited. It can be called before
|
事件循环策略 ¶
Policies is a low-level mechanism to alter the behavior of functions like
asyncio.get_event_loop()
. See also the main
policies section
了解更多细节。
Accessing Policies
|
返回当前进程范围的策略。 |
|
|
Set a new process-wide policy. |
|
|
Base class for policy objects. |