I have the following code that has 2 variables running 2 separate pools to process a bunch of tables and the progress should be reflected via the tqdm bar. I belive I have accomplished that but my problem now is there are new lines of progress bars with 0 progress and I can't figure out where it's coming from. What am I doing wrong?
CODE
from multiprocessing import Pool, Manager
from tqdm import *
from collections import deque
pbar = tqdm(position=0)
def task(tables_started, right_list, left_list, current_table, process):
if current_table not in tables_started:
tables_started.append(current_table)
if process == "left_process":
left_list.append(current_table)
else:
right_list.append(current_table)
# print(f"Starting {current_table} running on {process}.")
return True
else:
return False
def return_callback(result):
# global pbar
# print(result)
if result:
# print("updating")
pbar.update()
else:
# print("not updating")
pass
if __name__ == '__main__':
right_tables = deque()
manager = Manager()
for i in range(10):
right_tables.append("Table" + str(i))
left_tables = right_tables.copy()
left_tables.reverse()
# print(left_tables)
# print(right_tables)
tables_started = manager.list()
right_list = manager.list()
left_list = manager.list()
left_pool = Pool(processes=2)
right_pool = Pool(processes=2)
print(f"left_tables: {left_tables}")
print(f"right_tables: {right_tables}")
pbar.total = len(left_tables)
while left_tables:
left_table = left_tables.pop()
left_res = left_pool.apply_async(task, (tables_started, right_list, left_list, left_table, "left_process"), callback=return_callback)
right_table = right_tables.pop()
right_res = right_pool.apply_async(task, (tables_started, right_list, left_list, right_table, "right_process"), callback=return_callback)
left_pool.close()
right_pool.close()
left_pool.join()
right_pool.join()
# print(f"right_list: {right_list}")
# print(f"left_list: {left_list}")