[Twisted-Python] twisted on os x: cfreactor or kqreactor?

Bob Ippolito bob at redivi.com
Sat Apr 24 20:29:08 MDT 2004


On Apr 24, 2004, at 10:23 PM, Bob Ippolito wrote:

>
> On Apr 23, 2004, at 12:23 PM, rayg wrote:
>
>> i just created a fink package for PyKQeue
>> (http://sourceforge.net/tracker/index.php? 
>> func=detail&aid=940552&group_id=17203&atid=414256)
>> and this now allows me to use kqreactor.
>>
>> if i'm not not planning on using any cocoa functionality, is there any
>> advantage to use cfreactor over kqreactor on os x?
>>
>> i wasn't able to find any direct comparison between the mechanisms  
>> behind
>> kqreactor and cfreactor, but i did see that NSRunLoop is asynchronous,
>> like kqueue.  i've tested both reactors on a simple script and noticed
>> cfreactor doesn't stop() 75% of the time, so i'm inclined to just use
>> kqreactor, instead of tracking down why cfreactor isn't behaving...
>
> You need to use cfreactor or else twisted will block.  You basically  
> have no choice.
>
> If that script has a problem with SVN trunk of Twisted, then post the  
> script as a bug and I will fix it.  That said, stop() isn't  
> necessarily going to cause the program to exit (it doesn't call  
> CFRunLoopStop), but it should shut down twisted.  I've only  
> extensively tested it when used with a NSRunLoop with Cocoa stuff  
> going on, and never bothered with stop functionality because NSRunLoop  
> doesn't have a stop method at all (exiting is done via -[NSApplication  
> terminate] or an exit call).

I'm sorry, I read your message incorrectly.  If you are not using Cocoa  
functionality, use the default reactor or kqreactor (which will only  
work on 10.3).  CFRunLoop is designed to support Carbon (probably) and  
Cocoa applications.  There is no good reason to use it for a POSIX app  
unless you are using other event driven CoreFoundation code (highly  
unlikely, in Python anyway).

The way CoreFoundation does async socket I/O is to have a single  
network thread that posts events to the run loop thread.  In 10.2 and  
earlier it used select().  I am not sure if it is using kqueue or not  
in 10.3 (nor should I have to care).

-bob





More information about the Twisted-Python mailing list