Hi,
I'm using iPython right now to interactively set up a Twisted network. The script that I run in iPython describes best of what I have to do:
import router, pdb
# creates nodes which encapsulate RandomVector and VectorAdder objects
a = router.LocalNode(router.RandomVector, '/topic/a_c')
b = router.LocalNode(router.RandomVector, '/topic/b_c')
c = router.LocalNode(router.VectorAdder)
c.registerAsListener('/topic/a_c')
c.registerAsListener('/topic/b_c')
def conn():
global a
global b
a.onConnect()
b.onConnect()
router.r.loadOnConnect(conn)
router.STOMPconnect(router.r)
router.reactor.run()
What's happening is that conn() is being passed to a Twisted protocol, which runs conn() every time the connection is lost.
onConnect looks like this:
def onConnect(self):
self._lc = LoopingCall(self.advance)
self._lc.start(1)
Whenever onConnect gets run, I get the error:
TypeError: 'unbound method onConnect() must be called with RandomVector instance as first argument (got nothing instead)'
Does anyone know why this is happening?