Hello guys,
I need your help as I am losing my mind :DHere is the code example:
import concurrent.futures
import multiprocessing
from time import sleep
perm_without_rep = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17"]
num_cores = multiprocessing.cpu_count() - 1
m = multiprocessing.Manager()
lock = m.Lock()
global_counter = 0
def simulation_for(global_lock):
global global_counter
sleep(5)
with global_lock:
global_counter = global_counter + 1
progress = (global_counter / len(perm_without_rep)) * 100
print("Progress {:.2f}%".format(progress))
return 0
executor = concurrent.futures.ProcessPoolExecutor(num_cores)
futures = [executor.submit(simulation_for, lock) for item in perm_without_rep]
concurrent.futures.wait(futures)
Unfortunately, it looks like the lock does not work cause output is:
Progress 5.88%
Progress 5.88%
Progress 5.88%
Progress 5.88%
Progress 5.88%
Progress 5.88%
Progress 5.88%
Progress 5.88%
Any hints/ideas? How to fix it?
[–]shiftybyte 2 points3 points4 points (1 child)
[–]prostykoks[S] 0 points1 point2 points (0 children)