import queue
import threading

num_workers = 4

q = queue.Queue()

def do_work(item):
    print(item)

def worker():
    while True:
        item = q.get()
        if item is None:
            break
        do_work(item)
        q.task_done()

threads = []
for i in range(num_workers):
    t = threading.Thread(target=worker)
    t.start()
    threads.append(t)


for i in range(100):
    q.put(i)

for i in range(num_workers):
    q.put(None)

for t in threads:
    t.join()
