[Stackless] Context Switching and Queues

Richard Tew richard.m.tew at gmail.com
Sun Sep 2 23:52:31 CEST 2007

On 9/2/07, Andrew Francis <andrewfr_ice at yahoo.com> wrote:
> tasklets that can run, a chance to run. The important
> point is each time, a channel.send occurs, the
> producer is re-scheduled. I felt there was needless
> context switching.

Maybe I have skimmed past parts of your post which would suggest this
is not the case, but perhaps the 'preference' attribute on the channel
class will be of help?

-1 = prefer receiver  1 = prefer sender  0 no preference

I believe if you were to set this to 1 and a receiver was waiting on
the other end, the sender would stay the current tasklet and the
receiver would be put next in line to be scheduled.

>>> import stackless
>>> c = stackless.channel()
>>> def f():
...     print 'sending'
...     c.send(1)
...     print 'sent'
>>> def g():
...     print 'receiving'
...     c.receive()
...     print 'received'
>>> stackless.tasklet(g)().run()
>>> c.preference = 1
>>> stackless.tasklet(f)()
<stackless.tasklet object at 0x01618630>
>>> stackless.run()


More information about the Stackless mailing list