nhathuy07 commited on
Commit
dcb60b6
·
verified ·
1 Parent(s): f3ec82a

Use asyncio.gather for __query_ml_predict tasks

Browse files
Files changed (1) hide show
  1. main.py +3 -1
main.py CHANGED
@@ -492,9 +492,11 @@ async def generate_questions(request):
492
  # print(__ps)
493
 
494
  for z, _p in enumerate(__ps):
 
495
  ptasks.append(__query_ml_predict(qtype=(QType.STMT if z%2==1 else QType.WH), content=_p['content'], header=_p['header'], l=request.path_params.get('lang', lang.VI_VN), num_qs=request.path_params.get('num_qs', 5 * _p.get('count', 1)), token_limit = int(1024 * _p.get('count', 1))))
496
 
497
- __raw_outputs = [await p for p in ptasks]
 
498
 
499
  for pgph_i, o in enumerate(__raw_outputs):
500
  # print(o)
 
492
  # print(__ps)
493
 
494
  for z, _p in enumerate(__ps):
495
+ # __query_ml_predict is an awaitable
496
  ptasks.append(__query_ml_predict(qtype=(QType.STMT if z%2==1 else QType.WH), content=_p['content'], header=_p['header'], l=request.path_params.get('lang', lang.VI_VN), num_qs=request.path_params.get('num_qs', 5 * _p.get('count', 1)), token_limit = int(1024 * _p.get('count', 1))))
497
 
498
+ # __raw_outputs = [await p for p in ptasks]
499
+ __raw_outputs = asyncio.gather(*ptasks)
500
 
501
  for pgph_i, o in enumerate(__raw_outputs):
502
  # print(o)