medieval-yolo-api / test2.py
wjm55
Refactor app.py to remove model caching and initialize model per request. Update root endpoint and modify predict function to handle uploaded images. Change test.py to use variable for local app URL.
4160d5b
raw
history blame contribute delete
552 Bytes
from concurrent.futures import ThreadPoolExecutor
def process_item(item):
# Simulate a time-consuming task
import time
time.sleep(0.1)
return item * 2
def generate_data():
for i in range(10):
yield i
def process_data_in_parallel(data_generator):
with ThreadPoolExecutor(max_workers=4) as executor:
results = executor.map(process_item, data_generator)
return list(results)
# Usage example
data_generator = generate_data()
processed_data = process_data_in_parallel(data_generator)
print(processed_data)