我用python2.7编写了一个类(在linux下),它使用多个进程异步操作数据库。我在使用multiprocessing.Queue.put()和multiprocessing.Queue.get()时遇到了一个非常奇怪的阻塞行为,我无法解释。在
以下是我所做工作的简化版本:from multiprocessing import Process, Queue
class MyDB(object):
def __init__(self):
self.inqueue = Queue()
p1 = Process(target = self._worker_process, kwargs={"inqueue": self.inqueue})
p1.daemon = True
started = False
while not started:
try:
p1.start()
started = True
except:
time.sleep(1)
#Sometimes I start a same second process but it makes no difference to my problem
p2 = Process(target = self._worker_process, kwargs={"inqueue": self.inqueue})
#blahblah... (same as above)
@staticmethod
def _worker_process(inqueue):
while True:
#--------------this blocks depi