Re: [Twisted-Python] Stackless/Twisted integration again

Hi Simon and Colleages:
I note he recommends running a twisted server as a tasklet.
I do this so both the Twisted reactor and the Stackless scheduler can run without blocking each other.... The Twisted Reactor and the Stackless Schedule start their respective systems. Both the Stackless and Twisted run() method assume that the application has finished once the run() method returns. Here is simple example import stackless from twisted.internet import reactor def hello(): print "hello mom" stackless.tasklet(hello)() reactor.run() stackless.run() This programme will hang. Why? The Twisted reactor is running in the main tasklet and returns only after it has been stopped (which is never in this example). Only after the reactor has finished, will the stackless scheduler start. Of course, this is not the behaviour we want.
I have never used iterate(). I am having a hard time finding an example of iterate() in action. Perhaps I am wrong but I would assume iterate() is used in conjunction with something like reactor.interleave() so that something like a GUI can function properly.
I don't understand iterate() well enough but I think this will accidentally work sometimes. I don't have time to run your programme but off hand, this is what I think is happening: 1) Reactor tasklet is created. Since other tasklets are ahead of it, it is not running. 2) stackless.schedule() kicks off the scheduling, yielding the main tasklet and allowing the next schedulable tasklet to run 3) Eventually the Twisted reactor runs. It does stuff. You get results. However I don't believe it will yield after that.
I want to make the reactor a tasklet so it is included >in the scheduler.
Simon, stackless.tasklet(reactor.run)() will make the Twisted reactor into a tasklet. However you need a way to make it yield occasionally. That is why I use task.LoopingCall(stackless.schedule). One nice feature of this approach is that I do not have to alter the Reactor. I remember playing with PB a while ago. Here is the post: http://twistedmatrix.com/pipermail/twisted-python/2007-September/016000.html I am enclosing some sample code so you can play with it. The code may be a bit clunky because I was still learning. Heck I am still learning :-) Cheers, Andrew P.S - You may want to take out the 61 second sleep in the PBServer. And it was neat to actually meet Bruce Eckel at PyCon. ____________________________________________________________________________________ You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost. http://tc.deals.yahoo.com/tc/blockbuster/text5.com
participants (1)
-
Andrew Francis