[Stackless] channel.balance wrong?!

Chris Jacobson mainecoon at gmail.com
Sat Jul 11 22:31:28 CEST 2009


My point was to provide Paul a simple example of a situation he might be
getting into that could cause the problems he is seeing - use of channnel
preference which keeps the receiver from becoming active.
He doesn't send when channel.balance == 0, to keep the sending tasklet from
blocking.  He only sends when there is something waiting to receive.  If his
code uses the channel preference incorrect, that receiver is scheduled
rather than immediately made active when the sending tasklet sends, and if
the sending tasklet never reschedules itself, the receiver never gets time
to run and receive again.

- Chris
On Sat, Jul 11, 2009 at 11:57 AM, Andrew Francis <andrewfr_ice at yahoo.com>wrote:

>
> Hi Chris:
>
> On Sat, Jul 11, 2009 at 6:53 PM, Chris Jacobson<mainecoon at gmail.com>
> wrote:
> > I can think of at least one situation when this could occur, involving
> > Channel Preference of 1 (Sender):
> >
> > Channel N is created with preference 1
> > Tasklet?A and?B start
> > Tasklet A runs, receives on N, and blocks
> > Tasklet?B sees N has balance -1, so sends to N.? Due to Preference, B
> will
> > not yield, instead?A is placed at end of runnables queue.? The channel's
> > balance is now 0.
> > Tasklet?B continues running, sees N has a balance of 0, so does not send.
> > Repeat ad infinitum.? Tasklet?B never explicitly schedules or gets
> blocked
> > otherwise, and so?A never wakes up.
>
> Well one can create pathological cases. In regard to channels, pathological
> probably depends on inconsistently using the balance variable and the
> send()/receive() methods. In the example you stated, everything revolves
> around what "sees N has a a balance of 0, so does not send." What does
> "sees" mean?
>
> If b is in a loop and "sees" via a send(), then what happens is the second
> time, b blocks on a send() [which should have a balance of 0], the programme
> ends rather continues ad infiniuum. Why? All tasklets are now blocked.
>
> Try it:
>
> import stackless
>
> def a(ch):
>    message = ch.receive()
>    print message
>
>
> def b(ch):
>    while(1):
>       print ch.balance
>       ch.send("foo")
>
>
> if __name__ == "__main__":
>   ch = stackless.channel()
>   ch.preference = 1
>   stackless.tasklet(a)(ch)
>   stackless.tasklet(b)(ch)
>   stackless.run()
>
> In regards to Paul's problem. Posting code would be nice. However I have
> found that the more I use Stackless, the less I write code that looks at the
> channel.balance to make a scheduling decision.
>
> Cheers,
> Andrew
>
>
>
>
>
>
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20090711/66c3a777/attachment.htm>


More information about the Stackless mailing list