On Tuesday, October 20, 2009, at 01:20PM, "Hamish Sanderson" <hsander...@s-brandingsolutions.com> wrote: >Hi all, > >Trying to use Distributed Objects to communicate between PyObjC-based >processes on 10.5 and/or 10.6, but encountering various problems when >passing Python values, as illustrated below. The production code >currently only passes Python strings as arguments so I can work around >these issues for now by ensuring I always wrap them as NSStrings, but >it's going to create headaches if I start to use DO for more advanced >IPC. > >Anyone any thoughts? (Including suggestions for alternative LAN- >capable IPC options.)
Full DO support requires defining new protocols, which won't work on 64-bit builds. Even the limited DO support you need may or may not work because it is a low-level library that might interfere with PyObjC. I don't have unittests or sample code for this and hence cannot guarantee that this will work. I will look into your issues though, but not today. An alternative to DO is to use a native Python library (Twisted, XML-RPC, ...) combined with Bonjour. Ronald > >Thanks, > >Hamish > > >------- doserver.py ------- > >from Cocoa import * > >class Server(NSObject): > def test(self, arg): > print 'received:', arg > return NSString.stringWithString_(u"ok") > >receiveport = NSSocketPort.alloc().initWithTCPPort_(8080) >connection = >NSConnection.connectionWithReceivePort_sendPort_(receiveport, None) >server = Server.alloc().init() >connection.setRootObject_(server) >NSRunLoop.mainRunLoop().run() > > > >------- doclient.py ------- > >from Cocoa import * > >sendport = NSSocketPort.alloc().initRemoteWithTCPPort_host_(8080, >u"localhost") >connection = NSConnection.connectionWithReceivePort_sendPort_(None, >sendport) >proxy = connection.rootProxy() > >try: > print "reply", proxy.test(43) >except Exception, e: > print e ># doclient.py fails: ># ValueError: NSInvalidArgumentException - *** -encodeInt:forKey: only >defined for abstract class. ># Define -[NSConcretePortCoder encodeInt:forKey:]! > >print "reply", proxy.test(NSNumber.numberWithInt_(43)) # OK > >try: > print "reply", proxy.test([]) # OK on 10.6 >except Exception, e: > print e ># doclient.py fails on 10.5 ># ValueError: NSInvalidArgumentException - PyObjC: Encoding python >objects of type list is not supported > >print "reply", proxy.test(True) # OK > >print "reply", proxy.test(NSString.stringWithString_(u'hello')) # OK > >print "reply", proxy.test(u'hello') # OK on 10.5 ># doserver.py fails on 10.6: ># ValueError: NSInvalidArgumentException - -[OC_PythonUnicode >initWithBytes:length:encoding:]: ># unrecognized selector sent to instance 0x100261a80 > > > >-- > >Hamish Sanderson >Production Workflow Developer >Sun Branding Solutions Ltd >Tel: +44(0)1274 200 700 >www.s-brandingsolutions.com > > > > >_______________________________________________ >Pythonmac-SIG maillist - Pythonmac-SIG@python.org >http://mail.python.org/mailman/listinfo/pythonmac-sig > > _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig