Created
July 3, 2017 09:37
python2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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