I'm writing a library for use with Jupyter notebook. One of the things it does is asynchronously update progress in the notebook cell output. In the library I have a function:
def request_result():
start_result_calculation() # starts a calculation and returns immediately
asyncio.get_event_loop().create_task(report_progress())
result = wait_for_result() # waits for the calc to complete and returns the result
return result
If I now call result = request_result()
in a Jupyter notebook cell, the report_progress()
coroutine is never invoked. On the other hand, If I return the Task
back to the cell:
def calculate_result():
start_result_calculation()
return asyncio.get_event_loop().create_task(report_progress())
then when calculate_result()
is executed in a notebook cell the report_progress()
is invoked. Why is that, and is there a way to have the first function work as expected, spawning a background task and returning the final result?