[Stackless] stackless and system threads

Andrew Francis andrewfr_ice at yahoo.com
Sun Feb 4 17:35:49 CET 2007


Message: 4
Date: Sat, 3 Feb 2007 23:38:26 -0500
From: Andrew Dalke <dalke at dalkescientific.com>
Subject: Re: [Stackless] stackless and system threads
To: stackless at stackless.com
Message-ID:
<08463887e75ed1b939474ad177788776 at dalkescientific.com>
Content-Type: text/plain; charset=US-ASCII;
format=flowed

Hello Andrew:

I am thrilled that there is discussion on how to use
Stackless with system threads!

AD>It looks like the suggestion should be that all
AD>Stackless code should be run in the same thread.

Yes, this is the strategy I would recommend. 

AF> 1A. In my case, I have the Stackless and Twisted
AF> threads share a dequeue. I am being conservative;
I
AF> could probably use a channel.

AD>I'll remember to experiment with both variations.

Cool! 

I feel the less Twisted (or some other package) knows
about Stackless (and vice-versa), the better. I am
willing to take a performance hit to gain higher
modularity/loose coupling and safety. 

>This also busy waits, correct?  

You are correct. 

>And that last "schedule()" line should be indented by
>one?

No. I want schedule() to be called in each while()
iteration. The else is for "idle" processes. However
your observation is making me want to rethink the else
clause.

>It's effectively the same as the code I wrote, with a
>reordering for the loop condition to guarantee at
>least one looping.

>while 1:
>     stackless.run()
>     print "thread count", _thread_count
>     if _thread_count == 0:
>         break
>     time.sleep(0.02)

I disagree because I believe our code have different
goals. I think your loop is more like a Main tasklet
loop? My loop is a "dispatcher" tasklet. The loop is
constructed to allow multiple producers and consumers
to communicate in an asynchronous fashion. Hence the
dequeue. The consumer is the Stackless thread. The
producer is Twisted (more like the various Twisted
request handlers and deferreds).

So far, this approach is passing tests that made my
other approaches fail!

Since my application, a WS-BPEL processor, will
typically do considerable network I/O, I suspect in
most cases, it will be spending most of its time
waiting on Twisted. In my case, I don't want to 
throttle the Stackless loop with a sleep. 

Since I don't assume all tasklets are polite, I try to
call schedule() as much as possible (I could use
run(instructions). Think of the idle() process in a
typical windowing system's event loop. Currently I
have used the "idle" to schedule time based
activities. In the future, I will use Twisted taskLoop
to run a scheduler.

Cheers,
Andrew








 
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091

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



More information about the Stackless mailing list