Python async await on condition being true
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Python Async Await On Condition Being True
01:12 Accepted Answer Score 1
01:48 Thank you
--
Full question
https://stackoverflow.com/questions/5644...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #python3x #pythonasyncio
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Python Async Await On Condition Being True
01:12 Accepted Answer Score 1
01:48 Thank you
--
Full question
https://stackoverflow.com/questions/5644...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #python3x #pythonasyncio
#avk47
ACCEPTED ANSWER
Score 1
You would have to actively await:
async def runQueryAsync():
cursor = hive.connect('localhost').cursor()
await cursor.execute('select * from mytable', async_ = True)
while cursor.poll().operationState not in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):
await asyncio.sleep(1) # try each 1 second
return cursor.fetchall()
I'm not sure if you can await cursor.execute('select * from mytable', async_ = True), but if not just use cursor.execute('select * from mytable', async_ = True) , altough it would make sense to use it there. If it works with await in the execute it you may not need to use the while loop, since it should continue when the execute is finished:
async def runQueryAsync():
cursor = hive.connect('localhost').cursor()
await cursor.execute('select * from mytable', async_ = True)
return cursor.fetchall()