I was building a program to be deployed on windows. But I built it on Linux. I use multiprocessing and everything worked fine on Linux. But in windows, the processes do not run simultaneously and when they terminate, the program hangs in join statements. I read this was a known bug fixed on 3.7 but I am on 3.9.4.
The code:
def worker(day, queue, team, daily_jobs):
print(f"process {day} started")
initial_solution = solve_for_routes(
len(team), daily_jobs[day])
print(f"process {day} ended")
queue.put([day, initial_solution])
def main(pools, workday=6):
queue = multiprocessing.SimpleQueue()
team = ["bir", "iki", "üç"]
processes = []
for day in daily_jobs:
if not daily_jobs[day].empty:
processes.append(
multiprocessing.Process(target=worker, args=(day, queue, team, daily_jobs)))
for process in processes:
process.start()
for process in processes:
process.join()
for _ in processes:
q = queue.get()
plan[q[0]] = q[1]
named_plan = convert_to_named(plan, workday, team)
return named_plan
It prints:
process 0 started
process 0 ended
process 1 started
process 1 ended
process 2 started
process 2 ended
process 3 started
process 3 ended
process 4 started
process 4 ended
process 5 started
process 5 ended
And the program just hangs never making it further the join()
Again, this works perfectly fine on Linux.