15.2 asyncio--异步I/O事件库

本模块提供了单一线程并发事件处理多任务方式。

定时回调的例子:

import asyncio

 

def print_and_repeat(loop):

    print('Hello World')

    loop.call_later(2, print_and_repeat, loop)

 

loop = asyncio.get_event_loop()

loop.call_soon(print_and_repeat, loop)

loop.run_forever()

输出如下:

Hello World

Hello World

Hello World

Hello World

Hello World

在这个例子里,导入了异步事件处理库asyncio,接着定义函数 print_and_repeat,在这个函数里先打印字符串,在函数结束时调用事件循环loop来准备下一次回调的设置,也就是调用函数call_later()。在主函数里是先调用库asyncio来创建一个事件处理器loop,它是通过函数get_event_loop()返回,接着注册了一个事件call_soon(),最后调用函数run_forever()阻塞整个线程执行,直到退出为止。


蔡军生  QQ:9073204  深圳

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
07-13 10:08:02.266 403 12194 V EmulatedCamera_FakeCamera3: threadLoop: ReadoutThread: Timed out waiting for request 07-13 10:08:02.266 403 12194 V EmulatedCamera_FakeCamera3: threadLoop: ReadoutThread waiting for request 07-13 10:08:02.268 401 12178 I modules.usbaudio.audio_hal: in_read ret 0 07-13 10:08:02.273 401 12178 I modules.usbaudio.audio_hal: in_read ret 0 07-13 10:08:02.276 403 12194 V EmulatedCamera_FakeCamera3: threadLoop: ReadoutThread: Timed out waiting for request 07-13 10:08:02.277 403 12194 V EmulatedCamera_FakeCamera3: threadLoop: ReadoutThread waiting for request 07-13 10:08:02.278 401 12178 I modules.usbaudio.audio_hal: in_read ret 0 07-13 10:08:02.286 716 12304 E ActivityManager: ANR in com.winew.ddcsx (com.winew.ddcsx/.activity.MainActivity) 07-13 10:08:02.286 716 12304 E ActivityManager: PID: 11129 07-13 10:08:02.286 716 12304 E ActivityManager: Reason: Input dispatching timed out (1942a1b com.winew.ddcsx/com.winew.ddcsx.activity.MainActivity (server) is not responding. Waited 5002ms for MotionEvent(deviceId=11, source=0x00001002, displayId=0, action=DOWN, actionButton=0x00000000, flags=0x00000000, metaState=0x00000000, buttonState=0x00000000, classification=NONE, edgeFlags=0x00000000, xPrecision=8.5, yPrecision=15.2, xCursorPosition=nan, yCursorPosition=nan, pointers=[0: (1365.8, 1340.9)]), policyFlags=0x62000000) 07-13 10:08:02.286 716 12304 E ActivityManager: Parent: com.winew.ddcsx/.activity.MainActivity 07-13 10:08:02.286 716 12304 E ActivityManager: Load: 12.42 / 11.29 / 12.0 07-13 10:08:02.286 716 12304 E ActivityManager: ----- Output from /proc/pressure/memory ----- 07-13 10:08:02.286 716 12304 E ActivityManager: some avg10=0.00 avg60=0.00 avg300=0.00 total=249698 07-13 10:08:02.286 716 12304 E ActivityManager: full avg10=0.00 avg60=0.00 avg300=0.00 total=74789 07-13 10:08:02.286 716 12304 E ActivityManager: ----- End output from /proc/pressure/memory -----
07-15

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值