Message queue to transmit text between 2 processes


######################################################
"Message queue to transmit text between 2 processes"
######################################################


import multiprocessing
class message_queue_class(object):

    def __init__(self, name):
        self.name = name

    def do_something(self):
        proc_name = multiprocessing.current_process().name
        print 'my name: %s :Message received on queue: %s!' % (proc_name, self.name)

def process_2(q):
    obj = q.get()
    obj.do_something()

def process_1(q):
    queue.put(message_queue_class('Hi.. I am Neelkanth'))

if __name__ == '__main__':

    queue = multiprocessing.Queue()

    p = multiprocessing.Process(target=process_1, args=(queue,))
    p.start()
   

    p1 = multiprocessing.Process(target=process_2, args=(queue,))
    p1.start()
   
    # Wait for the process_2 to finish
    queue.close()
    queue.join_thread()
    p.join()