I am running multiples cells, where each of them run an async functions, and I want the cells to run consecutively, so I am using the function loop.run_until_complete to make sure each cell completes before running the next. Here is an example
import asyncio
import nest_asyncio
from timeit import default_timer
nest_asyncio.apply()
async def print_loop():
print('{0:<30}{1:>20}'.format('Function', 'Completed at'))
for i in range(3):
elapsed = default_timer() - START_TIME
completed_at = '{:5.2f}s'.format(elapsed)
print('{0:<30}{1:>20}'.format('[LOOP] %d' % i, completed_at))
time.sleep(0.5)
START_TIME = defualt_timer()
# This code will go on each cell
loop = asyncio.get_event_loop()
task = asyncio.ensure_future(print_loop())
loop.run_until_complete(task)
The run_until_complete blocks the next cell, but when running 3 or more cells I get the error
ERROR! Session/line number was not unique in database. History logging moved to new session
And the output start appearing in differents cells
I am running multiples cells, where each of them run an async functions, and I want the cells to run consecutively, so I am using the function loop.run_until_complete to make sure each cell completes before running the next. Here is an example
The run_until_complete blocks the next cell, but when running 3 or more cells I get the error
ERROR! Session/line number was not unique in database. History logging moved to new session
And the output start appearing in differents cellsAnd I get the following