Re: [Pyobjc-dev] Web Services Tool example broken
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2004-04-06 17:45:25
|
On Apr 6, 2004, at 12:47 PM, b.bum wrote: > On Apr 6, 2004, at 7:21 AM, Bob Ippolito wrote: >> The thing is that Foundation and Cocoa needs to know about the >> threads you are using in the same way that Python needs to know about >> them (via PyGILState_Ensure, etc.). There is a hook and notification >> that happens in Foundation when you detach your first NSThread (which >> this program never explicitly does), and you are otherwise supposed >> to at least call +[NSThread currentThread] from any raw pthread that >> expects to call Foundation or Cocoa code (which this program also >> never does). > > If the program doesn't call Foundation or Cocoa from the threads, then > there is no need to notify the ObjC runtime (or Foundation) that the > app has 'gone threaded'. It does call Foundation.. > And... as Ronald says. Worked before, doesn't work now... look to the > changes. Yeah, the new changes weren't complete, the GIL wasn't released during the call to NSApplicationMain, which didn't allow Python threads to run. I was close to catching this myself, but I got caught up trying to make Python do the correct thing, instead of just making it work ;) > Also -- in a chat w/Bob last night. If we need to tie something to > the lifetime of an NSThread, use NSThread's threadDictionary. That is > what it is far (and what it is used for by the Foundation). I think the new method stub autorelease pool management should take care of things (need to read Python threadstate management source code to verify) in the case of NSThread calling Python code. However, in order for a Python thread (pthread really) to *correctly* call into Foundation you must first perform an explicit NSThread.currentThread() and pool = NSAutoreleasePool.alloc().init() (not sure if that is necessarily the order). WebServicesTool only does one of these things, and I think it should even be creating a NSAutoreleasePool earlier in case an ObjC thing gets passed over the queue. The fact that it works is more of an exception than the rule, as it does not comply with the rules in Apple's Multithreading documentation. -bob |