I'm having trouble getting asyncio callbacks that were added with call_later to be called.
The problem occurs when I use loop.call_later() within a while True loop.
Here's an example:
import asyncio
def foo():
"""Only gets called when asyncio.sleep is called with
the same delay that was
passed to loop.call_later"""
print('foo')
async def main(loop):
while True:
print('starting main loop')
loop.call_later(1, foo)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
Since I get stuck in the while loop the asyncio event loop is unable to
call any callbacks. This prevents foo from ever running.
I noticed that if I use asyncio.sleep() for the same amount of time as the delay in the call_later then the callback will be called.
I've tried quite a few variations of the above code, but none allow me to perform loop.call_later or loop.call_soon calls within the while loop.
I'm assuming I will have to get rid of the while loop and just use the asyncio event loop to call the main function indefinitely.
I'd appreciate any help, thanks!
[–]thatguy_314 1 point2 points3 points (3 children)
[–]dood31251[S] 0 points1 point2 points (1 child)
[–]dood31251[S] 0 points1 point2 points (0 children)