The background class makes it easy to run an Axon system in a separate thread (in effect: in the background). This simplifies integration of Axon/Kamaelia code into other python code. See also Axon.Handle for a simple way to wrap a component in a thread safe way to access its inboxes and outboxes. Example UsageAt its simplest, you could run a Kamaelia task independently in the background - such as a simple network connection, that dumps received data into a thread safe queue, after de-chunking it into lines of text. NOTE: This example can be achieved more simply by using Axon.Handle. See the documentation of Axon.Handle to find out more.
We can now fetch items of data, from the queue when they arrive: received_line = queue.get() BehavourCreate one of these and start it running by calling its start() method. After that, any components you activate will default to using this scheduler. Only one instance can be used within a given python interpreter. The background thread is set as a "daemon" thread. This means that if your program exits, this background thread will be killed too. If it were not a daemon, then it would prevent the python interpreter terminating until the components running in it had all terminated too. Axon.background.backgroundclass background(threading.Thread)A python thread which runs the Axon Scheduler. Takes the same arguments at creation that Axon.Scheduler.scheduler.run.runThreads accepts. Create one of these and start it running by calling its start() method. After that, any components you activate will default to using this scheduler. Only one instance can be used within a given python interpreter. FeedbackGot a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording! Please leave you feedback here in reply to the documentation thread in the Kamaelia blog. -- Automatic documentation generator, 01 Feb 2010 at 04:00:28 UTC/GMT |
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