[Pythonmac-SIG] problems with Distributed Objects and PyObjC

Hamish Sanderson hsanderson at s-brandingsolutions.com
Tue Oct 20 13:20:12 CEST 2009

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  

Anyone any thoughts? (Including suggestions for alternative LAN- 
capable IPC options.)



------- 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()

------- doclient.py -------

from Cocoa import *

sendport = NSSocketPort.alloc().initRemoteWithTCPPort_host_(8080,  
connection = NSConnection.connectionWithReceivePort_sendPort_(None,  
proxy = connection.rootProxy()

	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

	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  
#    unrecognized selector sent to instance 0x100261a80


Hamish Sanderson
Production Workflow Developer
Sun Branding Solutions Ltd
Tel: +44(0)1274 200 700

More information about the Pythonmac-SIG mailing list