5 Postman - A Microprocess that performs deliveries!

Given we have outboxes and inboxes, it makes sense to have something that can handle deliveries between the two. For the purpose of this exercise, we'll create a microprocess that can look at a single outbox for a single component, take any messages deposited there and pass them the an inbox of another component. In terms of the component implementation so far we can use dataReady to check for availability of messages, recv to collect the message from the outbox, and send to deliver the message to the recipient inbox.

Exercise: Write a class called postman that subclasses microprocess with the following...


  • self.source - this should refer to the source component (expected type is to be a component)
  • self.sourcebox - this should refer to the name of the source component's outbox to check. eg "outbox"
  • self.sink - - this should refer to the destination (sink) component (expected type is to be a component)
  • self.sinkbox - this should refer to the name of the sink component's inbox to check. eg "inbox"

Behaviour: (methods)

  • __init__(self, source, sourcebox, sink, sinkbox)
    This should perform the following initialisation:
    • Call the super class initialiser (Hint: keyword "super" in python docs, and pydoc)
    • set the attributes listed above :-)

  • main(self)
    This implements the behaviour described above:
    • In a loop
      • yield control back periodically (eg yield 1 is sufficient)
      • Check to see if data is Ready on the source component's sourcebox.
      • If there is recv the data from that box, and send it to the sink component's sinkbox.

Answer HiddenShow Answer


  • Select from the above tabs to show the answer!


Given this, we can now start building interesting systems. We have mechanisms for enabling concurrency in a single process (microprocess & scheduler), a mechanism for adding communications (postboxes) to a microprocess (component) and a mechanism for enabling deliveries between components. Whilst we (the Kamaelia team) can see from an optimised version that the postman can actually be optimised out of the system, this simple mini-axon shows the core elements of Kamaelia quite nearly in a microcosm.

One full version of this mini-axon can be found here: Mini Axon Full, which should now be clear what it's doing how and why.

A simple example we can now create is a trivial system with one component creating some data and sending it to another one for display.

    class Producer(component):
        def __init__(self, message):
            self.message = message
        def main(self):
            while 1:
                yield 1
                self.send(self.message, "outbox")
    class Consumer(component):
        def main(self):
            count = 0
            while 1:
                yield 1
                count += 1 # This is to show our data is changing :-)
                if self.dataReady("inbox"):
                    data = self.recv("inbox")
                    print data, count
    p = Producer("Hello World")
    c = Consumer()
    postie = postman(p, "outbox", c, "inbox")
    myscheduler = scheduler()
    for _ in myscheduler.main():

Running the above system then results in the following output:

    Hello World 2
    Hello World 3
    Hello World 97
    Hello World 98

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)