summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2017-12-20 22:26:50 +0100
committerPatrick Simianer <p@simianer.de>2017-12-20 22:26:50 +0100
commita7b64caa0e22a974d352b091866d346da90c0ab5 (patch)
tree68f5a2fa0279f02e6e893202d7c00e23b21b5048
parent3b7fbea5f4b7b20564eba6d7a9a2420df4c0194f (diff)
python/mp.py
-rw-r--r--python/mp.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python/mp.py b/python/mp.py
new file mode 100644
index 0000000..93fa864
--- /dev/null
+++ b/python/mp.py
@@ -0,0 +1,31 @@
+import threading as mp
+from Queue import Queue
+from time import sleep
+from random import randint
+
+workers = []
+queues = []
+master_queue = Queue()
+
+def f(i, master, queue):
+ while True:
+ inp = master_queue.get(True)
+ print("got input %s"%inp)
+ sleep(randint(1,10))
+ queue.put(">>>> %d %s\n"%(i, inp))
+
+for i in range(10):
+ queue = Queue(1)
+ workers.append(mp.Thread(target=f, args=(i,master_queue,queue)))
+ queues.append(queue)
+ workers[i].start()
+
+for i in range(10000):
+ master_queue.put("msg-"+str(randint(1,1000)))
+
+while True:
+ for i in range(10):
+ if not queues[i].empty():
+ data = queues[i].get()
+ print data
+