aboutsummaryrefslogtreecommitdiff
path: root/spawn.py
blob: decea85da30cceca1c154e74f77a637af63890f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import queue
import threading
from lib import worker

num_worker_threads = 4

def input():
    return sys.stdin

q = queue.Queue()
threads = []
for i in range(num_worker_threads):
    thread_name = 'bob-' + str(i)
    t = threading.Thread(target=worker.worker, args=(q,), name=thread_name)
    t.start()
    threads.append(t)

for item in input():
    q.put(item)

# block until all tasks are done
q.join()

# stop workers
for i in range(num_worker_threads):
    q.put(None)
for t in threads:
    t.join()