标签:
按官方说法:
This module is OBSOLETE and is only provided on PyPI to support old projects that still use it. Please DO NOT USE IT FOR NEW PROJECTS! Use modern alternatives like the multiprocessing module in the standard library or even an asynchroneous approach with asyncio
threadpool 这个东东不推荐使用,那就跟上潮流,用用新的吧。
http://my.oschina.net/yangyanxing/blog/296052
锁之类的,POOL,MANAGER, LOCK,QUEUE之类,一应俱全。
# coding=utf8 from multiprocessing import Process, Queue, Manager, Pool import multiprocessing import os, time, random def write(q, lock): lock.acquire() for value in [‘A‘, ‘B‘, ‘C‘]: print ‘Put %s to queue...‘ % value q.put(value) #time.sleep(random.random()) lock.release() def read(q): while True: if not q.empty(): value = q.get(False) print ‘Get %s from queue.‘ % value time.sleep(random.random()) else: break if __name__ == ‘__main__‘: manager = multiprocessing.Manager() q = manager.Queue() lock = manager.Lock() p = Pool() pw = p.apply_async(write, args=(q, lock)) time.sleep(0.5) pr = p.apply_async(read, args=(q,)) p.close() p.join() print ‘all data write and read finished.‘
练习--python中的Queue与多进程(multiprocessing)
标签:
原文地址:http://www.cnblogs.com/aguncn/p/4967564.html