Hi Georg, seems i incidentally stumbled across the bug...
when I try to call the method "trigger" from an other program, PD always is crashing with the following backtrace:
I gues I am using something in a wrong way, but if I don't try to send the number to the outlet (line 31 in xmlrpc_server.py) there is no crash (e.g. a simple print in python works fine ...)
# ================================================ # PDxmlrpc class class PDxmlrpc(pyext._class): """ xmlrpc server """
# define in, outlets _inlets=1 _outlets=1
# start server def start_server_1(self, port): s = AsyncServer(port) s.start()
# trigger a specific number and # put it out to pd def trigger(self, number): self._outlet(1,number)
# ====================================================================== # xmlrpc server class AsyncServer(threading.Thread): """Starts the xmlrpc-server asynchron""" def __init__(self, port): threading.Thread.__init__(self) self.port = port def run(self): self.server = SimpleXMLRPCServer(("localhost", self.port)) self.server.register_instance(PDxmlrpc())
the problem is that in the last line you are creating a new instance of the PDxmlrpc class, although you want to output data over the one you created with the pyext object (which represents a PD external). You'd rather have to store and use a reference to your existing object, like in the following. (also xmlrpc wants to have non-None return values from the methods) The basic problem with that is that you create a circular reference which e.g. inhibits reloading of modules with pyext etc. This might not be a problem for you though, letting the server run forever.
# ================================================ # py script for pure data # """scripts to get messages from a xmlrpc server""" # # (c) 2005, Georg Holzmann, grh@mur.at # ================================================
# ================================================ # imports import pyext, SimpleXMLRPCServer, threading from SimpleXMLRPCServer import SimpleXMLRPCServer # ================================================ # PDxmlrpc class class PDxmlrpc(pyext._class): """ xmlrpc server """ # define in, outlets _inlets=1 _outlets=1 # start server def start_server_1(self, port): s = AsyncServer(port,self) s.start() # trigger a specific number and # put it out to pd def trigger(self, number): self._outlet(1,number) return True
# ====================================================================== # xmlrpc server class AsyncServer(threading.Thread): """Starts the xmlrpc-server asynchron""" def __init__(self, port,inst): threading.Thread.__init__(self) self.port = port self.inst = inst def run(self): self.server = SimpleXMLRPCServer(("localhost", self.port)) self.server.register_instance(self.inst) print "xmlrpc server serving on port ", self.port self.server.serve_forever()
# EOF # ======================================================================