0
在下面的代碼,回調()不是在repsective時間(現在+ 0.2and現在+ 0.1),還塞()調用,這裏有什麼問題ASYNCIO調度回調
def callback(n,loop):
print('Callback {} invoked at {}'.format(n,loop.time()))
def stopper(loop):
print("Stopper invoked at {}".format(loop.time()))
loop.stop()
event_loop = asyncio.get_event_loop()
try:
now =event_loop.time()
print('clock time: {}'.format(time.time()))
print('loop time: {}'.format(now))
print('Registering callbacks')
event_loop.call_later(now + 0.2,callback,1,event_loop)
event_loop.call_later(now + 0.1,callback,2,event_loop)
event_loop.call_later(now + 0.3,stopper,event_loop)
event_loop.call_soon(callback,3,event_loop)
print('Entering event loop')
event_loop.run_forever()
finally:
print('Closing event loop')
event_loop.close();
請更好地描述「不在各自的時間」意味着什麼。你什麼時候被調用,它什麼時候被調用? – deceze
callback()在當前+0.2和現在+0.1不被調用 – Rajeev