1. Microprocesses - A Generator with Context

Axon is built on top of generators with some added context. Whilst the most common version of this a user actually uses is called a component, this is a specialisation of the general concept - a generator with context.

Exercise: Write a class called microprocess (make sure you subclass "object" !) with the following methods:

  • __init__(self)
    • Takes no arguments. (aside from self)
    • into this put any initialisation you might need
  • main(self)
    • Takes no arguments. (aside from self)
    • This should be a generator that simply yields 1 value - specifically a 1

Answer HiddenShow Answer


  • Select from the above tabs to show the answer!


Clearly we can create a handful of these now:

    a = microprocess()
    b = microprocess()
    c = microprocess()

Calling their main method results in us being given a generator:

    >>> a.main()

    >>> b.main()

    >>> c.main()

We can then run these generators in the usual way (though these are fairly boring microprocesses):

    >>> for i in a.main():
    ... print "Value", i
    Value 1
    >>> for i in b.main():
    ... print "Value", i
    Value 1
    >>> for i in c.main():
    ... print "Value", i
    Value 1

OK, so we have a mechanism for adding context to generators, and we've called that a microprocess. Let's make it simple to set lots of these running.

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)