[Stackless] Advice on Writing a Stackless Reactor for Twisted

David Wyand TheHeadGnome at gnometech.com
Tue Jan 16 16:59:08 CET 2007


From: "Christopher Armstrong" <radix at twistedmatrix.com>
> On 1/16/07, David Wyand <TheHeadGnome at gnometech.com> wrote:
>> --- stacklessreactor.py ---
>>
>> __all__ = ['install']
>> import sys
>> import stackless
>> import uthread
>> from twisted.internet import selectreactor
>>
>> gReactor = None
>>
>> def ReactorTick():
>>     global gReactor
>>     while(gReactor.running != 0):
>>         gReactor.simulate()
>>         uthread.BeNice()
>
> It doesn't look like this does anything that a simple
> twisted.internet.task.LoopingCall(ReactorTick).start(0) wouldn't do.
> If you used that much simpler technique, you also wouldn't restrict
> yourself to the select reactor.

I'm certainly new at this so any guidance is greatly appreciated, although I 
don't want to hijack Andrew's original query.

In reading the API docs for t.i.task.LoopingCall() it sounds like this 
relies on the Twisted application loop being the driver rather than Twisted 
itself being treated as a tasklet and 'ticked' elsewhere.  Would your code 
fragment above not require a stackless.tasklet() call somewhere to make 
Twisted go along with the uthread-like application loop I've implemented in 
my maintest.py?  Or have I just completely misunderstood?

When I approached this problem I saw that two different paths could be 
taken.  The first would be to allow Twisted to be the driver and wrap all 
tasklets as deferreds (the approach I understand you've taken).  The second 
is to treat Twisted as just another tasklet along with all my other network, 
GUI, and game tasklets, which is what I've posted.  However I've not yet 
gone down either path far enough other than some basic AI simulations to 
discover any potential pitfalls.

Thanks.

- Dave
http://www.gnometech.com



_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list