[Stackless] Catching exception from tasklets

lars van Gemerden lars at rational-it.com
Sun Jun 24 10:17:09 CEST 2012


Hi Richard,

I have done some testing and running the following code in WingIDE results
in a different output from running it in Eclipse:

----------------------------------------------------------------------------------------------------------------
import stackless

class BombPasser(object):
    def __init__(self, name, other = None):
        self.name = name
        self.other = other
        if other:
            other.other = self
        self.channel = stackless.channel()
        self.tasklet = stackless.tasklet(self.run)()

    def run(self):
        print self.name, 'started'
        while True:
            counter = self.channel.receive() - 1
            print 'in %s: counter = %s' % (self.name, counter)
            if counter == 0:
                raise Exception(self.name + " did BOOM")
            self.other.channel.send(counter)
            stackless.schedule()

if __name__ == "__main__":

    a1 = BombPasser('bob')
    a2 = BombPasser('tim', other = a1)
    a1.channel.send(5)
    try:
        stackless.run()
    except Exception as e:
        print e.message
    print '=============== DONE ================='

------------------------------------------------------------------------------------------
Wing:

bob started
in bob: counter = 4
tim started
in tim: counter = 3
in bob: counter = 2
in tim: counter = 1
in bob: counter = 0
Unhandled exception in thread started by <bound method BombPasser.run of
<__main__.BombPasser object at 0x02583810>>

although the 'BOOM' exception does show up in the exception tool.

PyDev:

bob started
in bob: counter = 4
tim started
in tim: counter = 3
in bob: counter = 2
in tim: counter = 1
in bob: counter = 0
bob did BOOM
=============== DONE =================

What i thought would happen.

I have sent this as a bug report to WIngWare.

Cheers, Lars

On Sat, Jun 23, 2012 at 11:20 PM, Richard Tew <richard.m.tew at gmail.com>wrote:

> On Sun, Jun 24, 2012 at 8:23 AM, lars van Gemerden <lars at rational-it.com>
> wrote:
> > It was my inexeprience with WingIDE that did it. In the debug window it
> says
> > unhandled exception, but in the exception tool it shows that the
> exception
> > is caught normally.
> >
> > Am I correct in concluding that the stackless scheduler is not emptied
> upon
> > such an exception?
>
> Write some code to test this conclusion ;-)  It should only take you 30
> seconds.
>
> > PS: I will try the code you suggested for emptying the scheduler. I you
> > like, i'll let you know the result.
>
> No need :-)
>
> Cheers,
> Richard.
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>



-- 
====================================
Lars van Gemerden
lars at rational-it.com
+31 6 26 88 55 39
====================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20120624/05c2a9e5/attachment.html>


More information about the Stackless mailing list