[Pythonmac-SIG] Using UKKQueue with PyObjC

Bob Ippolito bob at redivi.com
Tue Mar 8 23:25:31 CET 2005


On Mar 8, 2005, at 16:59, Florian Munz wrote:

> Bob Ippolito <bob at redivi.com> wrote:
>
>> What you need to do here is:
>> (a) implement a __del__ that removes it as an observer or otherwise
>> ensure that the Controller object is never an observer after it's dead
>> (i.e. by making sure it never dies, or removing it manually before it
>> goes away).
>> (b) make sure it's alive for the duration that you want it to receive
>> notifications, by storing away a reference to it somewhere.. if you 
>> are
>> just testing and you want it to never go away, do self.retain()
>
> Thanks a lot, that solved all my problems and I know a significant bit
> more about PyObjC now ;-)

FYI the best way to debug a crash that happens on objc_msgSend is to 
use the same technique you would use when debugging Objective-C code: 
NSZombie.

Some information is available:
http://developer.apple.com/technotes/tn2004/tn2124.html
http://www.cocoadev.com/index.pl?DebuggingAutorelease

Essentially, what I do is this (with an --alias build):

env NSZombieEnabled=YES USE_PDB=1 ./dist/MyApp.app/Contents/MacOS/MyApp

If it's really bad, I'll use GDB:

env NSZombieEnabled=YES USE_PDB=1 gdb --args 
./dist/MyApp.app/Contents/MacOS/MyApp


USE_PDB is an environment variable that 
PyObjCTools.AppHelper.runEventLoop() inspects.  When it's set, it will:
(1) enable PyObjCTools.Debugging in verbose mode, so you get a stack 
trace at every exception that Objective-C sees (caught or otherwise).  
Python exceptions that cross the bridge will have additional 
information.
(2) on uncaught exceptions, it'll drop you to pdb (though the runloop 
will catch many exceptions)

Unfortunately, by the time runEventLoop kicks in it is too late to 
twiddle NSZombieEnabled and other Foundation debugging hooks, so you 
have to set it explicitly.

-bob



More information about the Pythonmac-SIG mailing list