import asyncio
import time
def callback(n, loop):
print('callback {} invoked at {}'.format(n, loop.time()))
async def main(loop):
now = loop.time()
print('clock time: {}'.format(time.time()))
print('loop time: {}'.format(now))
print('registering callbacks')
loop.call_at(now + 0.2, callback, 1, loop)
loop.call_at(now + 0.1, callback, 2, loop)
loop.call_soon(callback, 3, loop)
await asyncio.sleep(1)
event_loop = asyncio.get_event_loop()
try:
print('entering event loop')
event_loop.run_until_complete(main(event_loop))
finally:
print('closing event loop')
event_loop.close() entering event loop clock time: 1504688585.2024202 loop time: 5747.015 registering callbacks callback 3 invoked at 5747.031 callback 2 invoked at 5747.109 callback 1 invoked at 5747.218 closing event loop
在这个例子里调用函数 call_at() 来实现这个功能。
以上就是python中实现指定时间调用函数的方法讲解的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于python中实现指定时间调用函数的方法讲解的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84474