策略

An event loop policy is a global object used to get and set the current 事件循环 ,及创建新的事件循环。默认策略可以被 替换 with 内置替代 以使用不同事件循环实现,或被代入通过 自定义策略 可以覆盖这些行为。

The 策略对象 gets and sets a separate event loop per context . This is per-thread by default, though custom policies could define context differently.

Custom event loop policies can control the behavior of get_event_loop() , set_event_loop() ,和 new_event_loop() .

Policy objects should implement the APIs defined in the AbstractEventLoopPolicy abstract base class.

获取和设置策略

The following functions can be used to get and set the policy for the current process:

asyncio. get_event_loop_policy ( )

返回当前进程范围的策略。

asyncio. set_event_loop_policy ( policy )

Set the current process-wide policy to policy .

policy 被设为 None , the default policy is restored.

策略对象

The abstract event loop policy base class is defined as follows:

class asyncio. AbstractEventLoopPolicy

An abstract base class for asyncio policies.

get_event_loop ( )

Get the event loop for the current context.

Return an event loop object implementing the AbstractEventLoop 接口。

This method should never return None .

3.6 版改变。