ThreadPoolExecutor(workers) увеличивает использование памяти

я извлекаю текст из изображений (изображения в виде урлов) используя azure cognitive services через многопоточность в django, когда я передаю список урлов изображений в django API, он успешно извлекает текст из azure cognitive services, но использование памяти увеличивается всякий раз, когда я передаю список урлов изображений в django api и он не освобождает ее после завершения

django API

def multithreading(request):
        images_url = request['urls']
        with ThreadPoolExecutor(2) as ex:
            res = ex.map(azure_text, images_url )
        print(list(res))

Извлечение текстового кода

def azure_text(url)
        read_response = computervision_client.read(url.strip(), raw=True)
        # Get the operation location (URL with an ID at the end) from the response
        read_operation_location = read_response.headers["Operation-Location"]
        # Grab the ID from the URL
        operation_id = read_operation_location.split("/")[-1]

        # Call the "GET" API and wait for it to retrieve the results 
        while True:
            read_result = computervision_client.get_read_result(operation_id)
            if read_result.status not in ['notStarted', 'running']:
                break
            time.sleep(0.02)
        text = ''
        # Print the detected text, line by line
        if read_result.status == OperationStatusCodes.succeeded:
            for text_result in read_result.analyze_result.read_results:
        #         print(text_result.lines)
                for line in text_result.lines:
    #                 print(line.text)
                    text+=' '+line.text
        #             print(line.bounding_box)
        return text
Вернуться на верх