[Stackless] channel.balance wrong?!
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.
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>
> > 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
> > 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
> > 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):
> print ch.balance
> if __name__ == "__main__":
> ch = stackless.channel()
> ch.preference = 1
> 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.
> Stackless mailing list
> Stackless at stackless.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Stackless