<DIV>I've been working on integrating Compstrm </DIV>
<DIV>( <A href="http://compstrm.sourceforge.net">http://compstrm.sourceforge.net</A> ) and, while integration was pretty </DIV>
<DIV>easy, it got harder when I wanted to speed things up.</DIV>
<DIV> </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> </DIV>
<DIV>from twisted.internet import reactor</DIV>
<DIV>def _runUntilCurrentNew():<BR> if reactor.poll:<BR> p=reactor.poll<BR> reactor.poll=None<BR> p()<BR> _runUntilCurrentOld()</DIV>
<DIV> </DIV>
<DIV>_runUntilCurrentOld=reactor.runUntilCurrent<BR>reactor.runUntilCurrent=_runUntilCurrentNew</DIV>
<DIV><BR>reactor.poll=None</DIV>
<DIV>def _timeoutNew():<BR> if reactor.poll:<BR> return 0<BR> return _timeoutOld</DIV>
<DIV> </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> </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> </DIV>
<DIV>While I'm at it, here's my revised takedown code:</DIV>
<DIV><BR>class whenNoDelayedCalls:<BR> "I check for when there are no delayed calls."<BR> <BR> def __init__(self,granularity=1.0,func=reactor.stop):<BR> self.func=func<BR> self.granularity=granularity<BR> reactor.callLater(granularity,self)</DIV>
<DIV> def __call__(self):<BR> c=len(reactor.getDelayedCalls())<BR> if c or reactor.poll:<BR> reactor.callLater(self.granularity,self)<BR> else:<BR> self.func()</DIV>
<DIV> </DIV>
<DIV>def pollLoop(granularity=1.0,func=reactor.stop):<BR> "I run the reactor until there are no more delayed calls."<BR> <BR> whenNoDelayedCalls(granularity,func)<BR> 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> </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>