import multiprocessing
import time
q = multiprocessing.Queue()
for i in range(10):
q.put(i)
def b(worker):
while True:
job_id = q.get()
time.sleep(2)
print(f'{job_id=}, {worker=}')
if q.empty():
break
if __name__ == '__main__':
for i in range(4):
p = multiprocessing.Process(target=b, args=(i,))
p.start()
'''
خروجی من:
job_id=0, worker=0
job_id=0, worker=1
job_id=0, worker=2
job_id=0, worker=3
job_id=1, worker=0
job_id=1, worker=1
job_id=1, worker=2
job_id=1, worker=3
job_id=2, worker=0
job_id=2, worker=1
job_id=2, worker=2
job_id=2, worker=3
job_id=3, worker=0
job_id=3, worker=1
job_id=3, worker=2
job_id=3, worker=3
job_id=4, worker=0
job_id=4, worker=1
job_id=4, worker=2
job_id=4, worker=3
job_id=5, worker=0
job_id=5, worker=1
job_id=5, worker=2
job_id=5, worker=3
job_id=6, worker=0
job_id=6, worker=1
job_id=6, worker=2
job_id=6, worker=3
job_id=7, worker=0
job_id=7, worker=1
job_id=7, worker=2
job_id=7, worker=3
job_id=8, worker=0
job_id=8, worker=1
job_id=8, worker=2
job_id=8, worker=3
job_id=9, worker=0
job_id=9, worker=1
job_id=9, worker=2
job_id=9, worker=3
الان هر کار را هر چهار وورکر انجام میدهند در صورتی که در ویدیو هر کار را یک وورکر انجام میداد
این مشکل اول بنده است
'''