First of all I'm running this on jupyter notebook and that might be the cause of my confusion.
I have a function foo that does some IO operations:
def foo(): # Dom some stuff time.sleep(1.) return 'Finished' I want to be able to run this function in the background, so I decided to use run_in_executor:
future = asyncio.get_event_loop().run_in_executor(None, foo) Now the operation is non blocking and it's all fine, but if this future returns an error I want to catch it and stop the main program, so I decided to write a loop that keeps checking for the status of this future:
while True: time.sleep(0.1) if future.done(): # Do some stuff, like raising any caught exception The problem is that the future status is never being changed, inside the loop it's always pending.
If instead of checking in the loop I manually check the status of the future (in the jupyter notebook) it's going to be correctly marked as finished. This behavior confuses me...
How can I keep checking for the status of a future inside a loop formulation?