async semaphore fix

This commit is contained in:
xss 2022-03-13 07:35:08 +11:00
parent 67e47ab0fe
commit 9f02d1eece

View File

@ -32,8 +32,6 @@ LAUNCH_ALLOCATE_RANGE_SCALING = 1.5 # Scaling factor - launch allocation range i
# Do not run predictions if the ascent or descent rate is less than this value # Do not run predictions if the ascent or descent rate is less than this value
ASCENT_RATE_THRESHOLD = 0.5 ASCENT_RATE_THRESHOLD = 0.5
sem = asyncio.Semaphore(20)
def flight_profile_by_type(sonde_type): def flight_profile_by_type(sonde_type):
""" """
Determine the appropriate flight profile based on radiosonde type Determine the appropriate flight profile based on radiosonde type
@ -433,6 +431,7 @@ def predict(event, context):
return result return result
async def predict_async(event, context): async def predict_async(event, context):
sem = asyncio.Semaphore(20)
path = "telm-*/_search" path = "telm-*/_search"
payload = { payload = {
"aggs": { "aggs": {
@ -597,7 +596,7 @@ async def predict_async(event, context):
logging.debug("Start Predict") logging.debug("Start Predict")
jobs=[] jobs=[]
for serial in serials: for serial in serials:
jobs.append(run_predictions_for_serial(serial, serials[serial], reverse_predictions, launch_sites)) jobs.append(run_predictions_for_serial(sem, serial, serials[serial], reverse_predictions, launch_sites))
output = await asyncio.gather(*jobs) output = await asyncio.gather(*jobs)
for data in output: for data in output:
if data: if data:
@ -676,7 +675,7 @@ async def predict_async(event, context):
async def run_predictions_for_serial(serial, value, reverse_predictions, launch_sites): async def run_predictions_for_serial(sem, serial, value, reverse_predictions, launch_sites):
async with sem: async with sem:
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
# #