Python async await on condition being true
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:38 Accepted answer (Score 1)
02:28 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
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:38 Accepted answer (Score 1)
02:28 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()