diff options
author | ngharo <root@ngha.ro> | 2018-06-28 23:35:32 -0500 |
---|---|---|
committer | ngharo <root@ngha.ro> | 2018-06-28 23:35:32 -0500 |
commit | 49c83f0c693890f1e2df33919606362890bf726d (patch) | |
tree | d792e9ab08ae954ef95ac5cd1719cd3f2ef6c64b /spawn.py | |
parent | df15f0e7aa0e0e7d632e0859f003f547417bf2c2 (diff) | |
download | ansibots-49c83f0c693890f1e2df33919606362890bf726d.tar.xz ansibots-49c83f0c693890f1e2df33919606362890bf726d.zip |
WIP
Diffstat (limited to 'spawn.py')
-rw-r--r-- | spawn.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spawn.py b/spawn.py new file mode 100644 index 0000000..decea85 --- /dev/null +++ b/spawn.py @@ -0,0 +1,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() |