[Stackless] Stackless and Twisted Threads Redux

Carlos Eduardo de Paula carlosedp at gmail.com
Sat Jul 14 00:05:49 CEST 2007


Hi David,

Great work!! I always wanted to do something like that.... I love simulations...

As I followed the Stackless - Twisted integration and also talked
about it with Andrew, Chris Armstrong, we thought that Stackless and
Twisted works nicely together without threads.

Playing with your source, I found out that only changing the main.py
file, we can have the application running all into the same thread
where the Twisted reactor runs inside a tasklet and the stackless loop
drives it all.

Also I found benefits using this. Having two threads, I had about 40 -
50% CPU usage. Using the unique thread approach, the CPU dropped to
about 20 - 25%.

the main.py file became this:

from twisted.internet import reactor, task
import stacklessthread
import stackless
import webpages
import comm
import uthread
import tasklet

def twistedReactor():
    l = task.LoopingCall(uthread.BeNice)
    l.start(.0001)
    reactor.run()

if __name__ == "__main__":
    # Set up the Twisted to Stackless communications channels
    comm.SetupCommChannels()

    # Start Stackless work in another thread
    #reactor.callInThread(stacklessthread.run, comm.GetCommChannel(),
comm.GetDisplayChannel())
    tasklet.new("Twisted::Reactor::Run", twistedReactor)

    # Set up the web pages
    webpages.Setup()

    stacklessthread.run(comm.GetCommChannel(), comm.GetDisplayChannel())
    #reactor.run()


I kept the original calls just to show how simple it was to change the approach.

Hope it helps and other people could test it....

Carlos

On 7/13/07, David Wyand <TheHeadGnome at gnometech.com> wrote:
>
>
> Greetings All!
>
> Way back in January (I can't believe it!) I had a discussion with Andrew
> Francis and others here regarding Stackless and Twisted threads.  Since then
> I've read the discussion that using threads is perhaps not the most ideal
> method to have the two interoperate.
>
> However back in February and March, I pushed forward to build a test
> application that applied these principles.  It made use of Stackless,
> Twisted and Pygame to fly a bunch of AI space ships around.  Unfortunately
> other projects came up and I had to put it aside.
>
> Recently I've found time to finish it off and add some documentation for
> others to follow.  If you're interested you may download the Python source
> and documentation from my web site's Python page:
>
> http://www.gnometech.com/pythonproducts.shtml
>
> You may scan the readme, which includes screen shots, from that page.
> Enjoy!
>
> - Dave
> www.gnometech.com
>
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>


-- 
-------------------------------------------------------------------
Visit Stackless Examples Project
http://code.google.com/p/stacklessexamples/
Stackless Python - www.stackless.com
-------------------------------------------------------------------

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



More information about the Stackless mailing list