<DIV>I've been working on integrating Compstrm </DIV>
<DIV>( <A href="http://compstrm.sourceforge.net">http://compstrm.sourceforge.net</A>&nbsp;) and, while integration was pretty </DIV>
<DIV>easy, it got harder when I wanted to speed things up.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Basicly, compstrm uses yields to impliment a kind of light-weight </DIV>
<DIV>threads. So I needed to add background processing to the main reactor </DIV>
<DIV>loop. Here's the code I finally came up with:</DIV>
<DIV>&nbsp;</DIV>
<DIV>from twisted.internet import reactor</DIV>
<DIV>def _runUntilCurrentNew():<BR>&nbsp;&nbsp;&nbsp; if reactor.poll:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=reactor.poll<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.poll=None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p()<BR>&nbsp;&nbsp;&nbsp; _runUntilCurrentOld()</DIV>
<DIV>&nbsp;</DIV>
<DIV>_runUntilCurrentOld=reactor.runUntilCurrent<BR>reactor.runUntilCurrent=_runUntilCurrentNew</DIV>
<DIV><BR>reactor.poll=None</DIV>
<DIV>def _timeoutNew():<BR>&nbsp;&nbsp;&nbsp; if reactor.poll:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0<BR>&nbsp;&nbsp;&nbsp; return _timeoutOld</DIV>
<DIV>&nbsp;</DIV>
<DIV>_timeoutOld=reactor.timeout<BR>reactor.timeout=_timeoutNew<BR></DIV>
<DIV>Just using reactor.callLater, I could only get a speed of 90, in contrast to </DIV>
<DIV>the asyncore integration which was doing better than 12,000.</DIV>
<DIV>&nbsp;</DIV>
<DIV>By replacing runUntilCurrent and timeout, I managed to bump my speed up to better than 8,000, which seems reasonable, as Twisted is a bit </DIV>
<DIV>more "heavy weight" than asyncore. ;-)</DIV>
<DIV>&nbsp;</DIV>
<DIV>While I'm at it, here's my revised takedown code:</DIV>
<DIV><BR>class whenNoDelayedCalls:<BR>&nbsp;&nbsp;&nbsp; "I check for when there are no delayed calls."<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def __init__(self,granularity=1.0,func=reactor.stop):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.func=func<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.granularity=granularity<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.callLater(granularity,self)</DIV>
<DIV>&nbsp;&nbsp;&nbsp; def __call__(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c=len(reactor.getDelayedCalls())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if c or reactor.poll:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.callLater(self.granularity,self)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.func()</DIV>
<DIV>&nbsp;</DIV>
<DIV>def pollLoop(granularity=1.0,func=reactor.stop):<BR>&nbsp;&nbsp;&nbsp; "I run the reactor until there are no more delayed calls."<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; whenNoDelayedCalls(granularity,func)<BR>&nbsp;&nbsp;&nbsp; reactor.run()<BR></DIV>
<DIV>This gives me an approximate equivalent to the asyncore poll loop,</DIV>
<DIV>at least when there's no threads or sockets running. ;-)</DIV>
<DIV>&nbsp;</DIV><BR><BR>Bill la Forge<br>http://www.geocities.com/laforge49/<p><font face=arial size=-1>
<a href="http://in.rd.yahoo.com/specials/mailtg/*http://yahoo.shaadi.com/india-matrimony/" target="_blank">
<b>Yahoo! India Matrimony</a>:</b> Find your partner 
<a href="http://in.rd.yahoo.com/specials/mailtg2/*http://yahoo.shaadi.com/india-matrimony/community.php" target="_blank">online</a>.</font>