Re: [Pyobjc-dev] Re: FYI: Open Source Scripting Layer For Cocoa
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-06-13 13:28:29
|
On Friday, Jun 13, 2003, at 05:25 America/New_York, Just van Rossum wrote: > That said, I feel quite strongly that any networking Cocoa app should > either use asynchronous I/O or threads, which complicates the matter > quite a bit. Me too, it makes Python/PyObjC look really bad if we offer spinning beach balls with an unresponsive UI. > > It's possible to run a twisted reactor (= twisted event loop) in a > different thread (I've briefly played with that, works like a charm). > It > *might* be possible to build a twisted reactor that's integrated with > the main Cocoa event loop, but that is likely quite hard. The > WebServicesTool demo uses xmlrpclib in a worker thread (in CVS at > least, > I recently did a lot of work on it), but the complicatated thing about > it is that as soon as you use Cocoa stuff from a different thread, you > have to deal with autorelease pools. I've found it impossible to do > even > the simplest Cocoa things (eg obj.performSelectorOnMainThread_etc.) in > PyObjC without implicitly creating autoreleased objects, so you don't > really get around wrapping your code in > NSAutoreleasePool.pyobjcPushPool() / NSAutoreleasePool.pyobjcPopPool() > blocks. See WebServicesTool for how that's done. I've been meaning to develop a CFRunLoop reactor for Twisted for months now. Basically, you would be replacing the select() mechanism with something that used CFRunLoop, CFSocket (can probably use the existing functionality and just have the CFSocket use the fileno from them), and CFTimer. Unfortunately, not all of this stuff is wrapped in PyObjC or Python 2.3 yet so I'm expecting it to entail a fair amount of pain-in-the-ass C code with lots of structures and callbacks into Python (yay CFSocket). That said, if I find the time in the near future, it should be in a late release of Twisted 1.0.X or an early release of Twisted 1.1.X. I'll make a post to this list when it's in Twisted CVS in case anyone wants to play with it. If anyone wants to wrap more of CoreFoundation for Python in the meantime, I surely wouldn't complain :) -bob |