Skip to content

Instantly share code, notes, and snippets.

@raycool
Created July 3, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raycool/cf3d1fa9d3dfb2fcca0fae2adfeddf0a to your computer and use it in GitHub Desktop.
Save raycool/cf3d1fa9d3dfb2fcca0fae2adfeddf0a to your computer and use it in GitHub Desktop.
python2
#coding:utf-8
import os, sys, time
from multiprocessing import Pool, Queue, Manager
def out(queue):
while True:
item = queue.get()
print item
time.sleep(0.01)
class Data(object):
def __init__(self):
self.pool = Pool(2)
self.queue = Manager().Queue()
def put(self,item):
self.queue.put(item)
def start(self):
print self.queue.qsize()
for _ in range(2):
self.pool.apply_async(out,(self.queue,))
if __name__ == '__main__':
data = Data()
for i in range(1000):
data.put(i)
data.start()
data.pool.close()
data.pool.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment