Exemplo n.º 1
0
    def testKillOnChannel(self):
        
        c = stackless.channel()
        
        def child(r):
            r.b1 = c.balance
            r.rc1 = stackless.getruncount()
            r.cur1 = stackless.getcurrent()
            r.blocked1 = r.cur1.blocked
            r.alive1 = r.cur1.alive
            try:
                c.receive()
            finally:
                r.b2 = c.balance
                r.rc2 = stackless.getruncount()
                r.cur2 = stackless.getcurrent()
                r.blocked2 = r.cur2.blocked
                r.alive2 = r.cur2.alive

        class result: pass

        r = result()
        ch = stackless.tasklet(child)(r)
        
        stackless.schedule()

        ch.kill()

        self.assertEquals((0, 0), (r.b1, r.b2))
        self.assertEquals((2, 2), (r.rc1, r.rc2))
        self.assertTrue(r.cur1 == r.cur2)
        self.assertEquals((False, False), (r.blocked1, r.blocked2))
        self.assertEquals((True, True), (r.alive1, r.alive2))
Exemplo n.º 2
0
    def testChannel(self):
        
        c = stackless.channel()
        
        recvd = []
        
        def ch1():
            for i in range(10):
                recvd.append(c.receive())

        def ch2():
            for i in range(10):
                c.send(i)

        child1 = stackless.tasklet(ch1)()
        child2 = stackless.tasklet(ch2)()

        self.assertEquals(3, stackless.getruncount()) #main
        
        while stackless.getruncount() > 1:
            stackless.schedule()

        self.assertEquals(range(10), recvd)
        
        self.assertEquals(1, stackless.getruncount()) #main
Exemplo n.º 3
0
    def testChannel(self):

        c = stackless.channel()

        recvd = []

        def ch1():
            for i in range(10):
                recvd.append(c.receive())

        def ch2():
            for i in range(10):
                c.send(i)

        child1 = stackless.tasklet(ch1)()
        child2 = stackless.tasklet(ch2)()

        self.assertEquals(3, stackless.getruncount())  #main

        while stackless.getruncount() > 1:
            stackless.schedule()

        self.assertEquals(range(10), recvd)

        self.assertEquals(1, stackless.getruncount())  #main
Exemplo n.º 4
0
    def testKillOnChannel(self):

        c = stackless.channel()

        def child(r):
            r.b1 = c.balance
            r.rc1 = stackless.getruncount()
            r.cur1 = stackless.getcurrent()
            r.blocked1 = r.cur1.blocked
            r.alive1 = r.cur1.alive
            try:
                c.receive()
            finally:
                r.b2 = c.balance
                r.rc2 = stackless.getruncount()
                r.cur2 = stackless.getcurrent()
                r.blocked2 = r.cur2.blocked
                r.alive2 = r.cur2.alive

        class result:
            pass

        r = result()
        ch = stackless.tasklet(child)(r)

        stackless.schedule()

        ch.kill()

        self.assertEquals((0, 0), (r.b1, r.b2))
        self.assertEquals((2, 2), (r.rc1, r.rc2))
        self.assertTrue(r.cur1 == r.cur2)
        self.assertEquals((False, False), (r.blocked1, r.blocked2))
        self.assertEquals((True, True), (r.alive1, r.alive2))
Exemplo n.º 5
0
    def testChannelException(self):

        c = stackless.channel()

        result = []

        def ch1():
            for i in range(2):
                try:
                    result.append(c.receive())
                except TestError, te:
                    result.append(te)
Exemplo n.º 6
0
    def testChannelException(self):


        c = stackless.channel()

        result = []

        def ch1():
            for i in range(2):
                try:
                    result.append(c.receive())
                except TestError, te:
                    result.append(te)
Exemplo n.º 7
0
    def testExceptionOnChannel(self):
        
        c = stackless.channel()
        
        def child(r):
            r.b1 = c.balance
            try:
                c.receive()
            except TestError:
                r.b2 = c.balance

        class result: pass

        r = result()
        ch = stackless.tasklet(child)(r)
        
        stackless.schedule()

        ch.raise_exception(TestError)
        
        self.assertEquals((0, 0), (r.b1, r.b2))
Exemplo n.º 8
0
    def testExceptionOnChannel(self):

        c = stackless.channel()

        def child(r):
            r.b1 = c.balance
            try:
                c.receive()
            except TestError:
                r.b2 = c.balance

        class result:
            pass

        r = result()
        ch = stackless.tasklet(child)(r)

        stackless.schedule()

        ch.raise_exception(TestError)

        self.assertEquals((0, 0), (r.b1, r.b2))