I may break the code up for readability reasons. So
async coro_top():
print('top')
print('1')
# ... More asyncio code
print('2')
# ... More asyncio code
... into something like
async coro_top():
print('top')
await coro_1()
await coro_2()
async coro_1()
print('1')
# ... More asyncio code
async coro_2()
print('2')
# ... More asyncio code
However, the extra await
s mean that these are not strictly equivalent
Another concurrent task can run code between
print('top')
andprint('1')
, so makes race conditions a touch more likely for certain algorithms.There is (presumably) a slight overhead in yielding the event loop
So is there a way of calling a coroutine without yielding the event loop in order to avoid the above?