[Stackless] channel.balance wrong?!

Kristján Valur Jónsson kristjan at ccpgames.com
Sat Jul 11 10:55:53 CEST 2009


It probably gets scheduled _after_ you output the debug:
1) A print debug
2) A preemptive interrupt
3) B check balance
...

Why don't you try:
old = stackless.set_atomic(True)
try:
    output_debug('I am about to receive')
    channel.receive()
finally:
    stackless.set_atomic(old)


If you are using preemptive scheduling in stackless, you have to guard logic with atomic sections.
See also:
http://zope.stackless.com/wiki/Samples for an atomic context manager.
K

> -----Original Message-----
> From: stackless-bounces at stackless.com [mailto:stackless-
> bounces at stackless.com] On Behalf Of Paul Sijben
> Sent: 11. júlí 2009 08:37
> To: Jeff Senn
> Cc: stackless at stackless.com
> Subject: Re: [Stackless] channel.balance wrong?!
> 
> What I see in my trace is that tasklet A receives on a channel, some
> time later (can look up an exact number of milliseconds but it was
> several lines of debug output and some network communication later)
> tasklet B checks the balance and finds it to be 0 (yet A is still
> waiting).
> 
> So no race contidtion there. :-(
> 
> Jeff Senn wrote:
> > [unlikely that you haven't thought of this, but on the off-chance it
> > helps;
> > and because if channel->balance were ever broken I would expect a
> > *lot* more to
> > be wrong...]
> >
> > Are you doing "preemptive" scheduling?  Is there a race-condition
> > where the balance is checked just prior to a receiver blocking?
> > (this would be the classic all-consumer-busy-but-one-about-to-be-
> ready
> > race condition you would only see under heavy load...)
> >
> > On Jul 10, 2009, at 10:48 AM, Paul Sijben wrote:
> >
> >> I tracked down a bug in my code that occasionally popped up to
> >> channel.balance being wrong sometimes.
> >>
> >> Some part of my code can not afford to block, so it checks the
> balance
> >> wheter it should send something into the channel. If there is a
> receiver
> >> waiting on it, that is fed by a send and the sender  will not block.
> Now
> >> I find that just occasionally the process stalls because there is a
> >> receiver waiting but the sender does not send as channel.balance==0
> >> instead of -1!
> >>
> >> I am running the current 2.6.2 version of stackless
> >> (Python 2.6.2 Stackless 3.1b3 060516 (python-2.6.2:73804M, Jul  3
> 2009,
> >> 11:33:51) )
> >>
> >> Is this issue known, and possibly solved in svn?
> >>
> >> Paul
> >>
> >>
> >> --
> >> Paul Sijben                        tel: +31334566488
> >> Eemvalley Technology BV           fax: +31334557523
> >> the Netherlands                    http://eemvalley.com
> >> -----------------------------------------------------
> >> EemValley Technology werft python & wxpython
> >> programmeurs: http://www.eemvalley.nl/jobs
> >>
> >>
> >> _______________________________________________
> >> Stackless mailing list
> >> Stackless at stackless.com
> >> http://www.stackless.com/mailman/listinfo/stackless
> >>
> >
> 
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless





More information about the Stackless mailing list