The following code is about the communication between two child processes by queue. I can not figure it out that why the self.q.qsize() is zero and self.q.get() is blocked in the Function "ACT"???.... Since the counter shows the queue is full...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from multiprocessing import Process
import multiprocessing
import time
from Queue import Queue
class Test():
def __init__(self):
self.q = Queue(1)
def ACT(self):
while True:
print "B momoent queue size: %s" %self.q.qsize()
print self.q.get()
time.sleep(1)
def counter(self):
for i in range(5,10):
if not i == 5:
print "Hello1"
print self.q.full()
self.q.join()
print "Hello2"
self.q.put(str(i))
print "A moment queue size: %s" % self.q.qsize()
if __name__ == '__main__':
foo = Test()
qw = Process(target=foo.counter)
qw.start()
qr = Process(target=foo.ACT)
qr.start()
qw.join()
print "End"