Re: [Pyobjc-dev] using threadedselectreactor from PyObjC plug-in?
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-07-13 01:18:43
|
On Jul 12, 2005, at 3:01 PM, yt...@em... wrote: > > On Tue, 12 Jul 2005 14:27:39 -1000, "Bob Ippolito" <bo...@re...> > said: > >> >> On Jul 12, 2005, at 2:09 PM, yt...@em... wrote: >> >> >>> I read (but admit, did not fully comprehend) the following w/ >>> quite some interest: >>> >>> http://bob.pythonmac.org/archives/2005/04/17/twisted-and-foreign- >>> event-loops/ >>> >>> I'd been using cfreactor in my PyObjC plug-ins with some >>> success, but I noticed a comment about it being 'deadweight' >>> now (or has been for some months). >>> >>> So, I'm trying to adapt my plug-ins to using the >>> threadedselectreactor, but I'm experiencing difficulties. >>> I presume it has something to do w/ the bit about: >>> >>> In order to integrate with foreign event loops, >>> threadedselectreactor sports an extension to the reactor >>> interface: interleave(waker). >>> >>> In a plug-in context, I don't understand how to 'do the >>> waker stuff' appropriately -- I presume it's necessary as >>> not doing it leads to the beach-balling of my plug-ins' host >>> application :-) >>> >>> I've had a look at the WebServicesTool-CocoaBindings example >>> but AFAICT, that uses PyObjCTools.AppHelper's runEventLoop and >>> callAfter -- are those things I should try to invoke from >>> within my plug-ins? >>> >> >> callAfter is fine to invoke from anything that uses NSRunLoop. >> > > Thanks. > > I think I have been able to get this working. On the off-chance > someone else gets stuck on this, the following is essentially what > ended up working for me: > > from twisted.internet import threadedselectreactor > reactor = threadedselectreactor.install() > #reactor.run() # do not do this > > from PyObjCTools import AppHelper > reactor.interleave(AppHelper.callAfter) > > When using cfreactor, I had reactor.run() in my code, but this > doesn't appear to be a good idea with the way I'm doing things > now. cfreactor was dumb, that method shouldn't have been called run in the first place. It didn't (under most circumstances) do what run is supposed to do according to Twisted's reactor spec. threadedselectreactor fixes that by calling it something else (interleave). Anyway, I wouldn't recommend doing the interleave at module-level most of the time, but for a plugin it's fine. The threadedselectreactor examples use threadedselectreactor in the idiomatic way, so you should do what they do (in general). -bob |