[Stackless] stackless and system threads
andrewfr_ice at yahoo.com
Sun Feb 4 17:35:49 CET 2007
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
<08463887e75ed1b939474ad177788776 at dalkescientific.com>
Content-Type: text/plain; charset=US-ASCII;
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;
AF> could probably use a channel.
AD>I'll remember to experiment with both variations.
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
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
>It's effectively the same as the code I wrote, with a
>reordering for the loop condition to guarantee at
>least one looping.
> print "thread count", _thread_count
> if _thread_count == 0:
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.
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
Stackless mailing list
Stackless at stackless.com
More information about the Stackless