I have been working to develop an algorithm in python in which certain tasks need to be computed in parallel. I am using threadpoolexecutor to do it. My specific section of code is:
with concurrent.futures.ThreadPoolExecutor(max_workers=number_of_threads) as executor:
for chunk in NearEndChunks:
test = ED.EchoDetection()
futures = {executor.submit(test.echoDetection, chunk, FarEndChunks, i, i + chunk_shift): i for i in
range(zero_ms, delay_line_max, chunk_shift)}
if ED.EchoDetection.FOUND.value == 1:
print(
f'Echo detected and indexes are as : near end index = {test.NEARINDEX.value} and '
f'Farend '
f'index = {test.FARINDEX.value}')
break
The problem I am facing :
This function test.echoDetection doesn't return anything so futures have nothing to do with this code.
Problem is that when I run this code, it creates multiple threads as mentioned in variable number_of_threads which is 15 in my case for now but it doesn't compute all the tasks and then new threads are being created and it goes on and on till I get following error:
Process finished with exit code -1073741819 (0xC0000005)
Solution I want:
How do I make it work that it completes all the tasks and then new loop runs? In java there is ThreadPoolExecutor#getActiveCount(). What's the alternative for it in python. Also, is there any other better approach to perform these calculations?
Regards,
Khubaib
User contributions licensed under CC BY-SA 3.0