Debugging Kamaelia Systems
January 13, 2008 at 02:56 PM | categories: python, oldblog | View Comments
One thing that is particularly useful when debugging Kamaelia systems - especially servers - is the ability to dump out what's running. Fortunately Kamaelia provides a mechanism to introspect the scheduler, so you can do this as follows:
This produces output of the following kind:
import timeNote: this construct won't shutdown.
import Axon
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
class PeriodicWakeup(Axon.ThreadedComponent.threadedcomponent):
interval = 300
def main(self):
while 1:
time.sleep(self.interval)
self.send("tick", "outbox")
class WakeableIntrospector(Axon.Component.component):
def main(self):
while 1:
Q = [ q.name for q in self.scheduler.listAllThreads() ]
Q.sort()
self.send("*debug* THREADS"+ str(Q), "outbox")
self.scheduler.debuggingon = False
yield 1
while not self.dataReady("inbox"):
self.pause()
yield 1
while self.dataReady("inbox"):
self.recv("inbox")
Pipeline(
PeriodicWakeup(),
WakeableIntrospector(),
ConsoleEchoer(),
).activate()
This produces output of the following kind:
*debug* THREADS['Kamaelia.Chassis.Pipeline.Pipeline_11', 'Kamaelia.Chassis.Pipeline.Pipeline_7', 'Kamaelia.Internet.TCPClient.TCPClient_9', '__main__.Listener_10', '__main__.PeriodicWakeup_5', '__main__.WakeableIntrospector_6']This turns out to be, as you might expect, to be particularly useful.