Skip to content

Commit af8475f

Browse files
authored
Multithreading on get complete entities
1 parent 034fbbf commit af8475f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/schema/schema_manager.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import requests
55
import unicodedata
6+
import concurrent.futures
67
from flask import Response
78
from datetime import datetime
89

@@ -827,10 +828,16 @@ def _get_metadata_result(token, entity_dict, metadata_scope:MetadataScopeEnum, p
827828
"""
828829
def get_complete_entities_list(token, entities_list, properties_to_skip = []):
829830
complete_entities_list = []
830-
831-
for entity_dict in entities_list:
832-
complete_entity_dict = get_complete_entity_result(token, entity_dict, properties_to_skip)
833-
complete_entities_list.append(complete_entity_dict)
831+
832+
# Use a pool of threads to execute the time-consuming iteration asynchronously to avoid timeout - Zhou 2/6/2025
833+
with concurrent.futures.ThreadPoolExecutor() as executor:
834+
helper_func = lambda args: get_complete_entity_result(args[0], args[1], args[2])
835+
args_list = [(token, entity_dict, properties_to_skip) for entity_dict in entities_list]
836+
837+
# The order of donors/organs/samples lists are not gurenteed with using `executor.submit()`
838+
# `executor.map()` maintains the same order of results as the original submitted tasks
839+
for result in executor.map(helper_func, args_list):
840+
complete_entities_list.append(result)
834841

835842
return complete_entities_list
836843

0 commit comments

Comments
 (0)