wiredfool

PyObjC Noodling

I’ve been noodling a bit with PyObjC, the Python-Objective C Cocoa bridge. So far, I’ve made some pretty good progress for not knowing either language or the api. In about one ti-battery worth of whacking, I got a python library communicating with a cocoa interface, and even included a post to weblog menu item. I think all hello world apps will now post to a weblog, just as all other apps expand till they read email.

I started to run into trouble with threading, specifically, NSAutoreleasePool and what happens when you kick off a thread.

    NSThread.detachNewThreadSelector_toTarget_withObject_
          ("startThread:",self,self) 
    ....
 
  def startThread_(self,sender):
    pool=NSAutoreleasePool.alloc().init()
    self.bot.go()
    pool.release()

This code kicks off a backend process that should not exit. The thread spawing works, I can communicate with the back end with events appearing on screen. The console log shows some objects that were leaked without an autorelease pool, an attempt to retain the autorelease pool, and then when I type the first character in the interface, the program dies with a signal 10 SIGBUS.

I should probably try this with python threads to see what happens from that side of things.

No comments

No comments yet. Be the first.

Leave a reply

You must be logged in to post a comment.