def testMultiTask(self): local = TaskLocal() def t(): local.piet = [] for i in range(10): local.piet.append(i) Tasklet.yield_() self.assertEquals(range(10), local.piet) t1 = Tasklet.new(t)() t2 = Tasklet.new(t)() Tasklet.join_all([t1, t2]) self.assertEquals(2, len(local._d.keys( ))) #the 2 tasks are sill around, so local keeps their values #check that values are gone from dict #when tasks are gone del t1 del t2 #we need to yield, because our 2 tasks were suspended by the join #yield will run the scheduler again, so our tasks can properly finish #the only strange thing is we need 2 yields for python, stackless requires just 1 Tasklet.yield_() Tasklet.yield_() self.assertEquals([], local._d.keys())
def testMultiTask(self): local = TaskLocal() def t(): local.piet = [] for i in range(10): local.piet.append(i) Tasklet.yield_() self.assertEquals(range(10), local.piet) t1 = Tasklet.new(t)() t2 = Tasklet.new(t)() Tasklet.join_all([t1,t2]) self.assertEquals(2, len(local._d.keys())) #the 2 tasks are sill around, so local keeps their values #check that values are gone from dict #when tasks are gone del t1 del t2 #we need to yield, because our 2 tasks were suspended by the join #yield will run the scheduler again, so our tasks can properly finish #the only strange thing is we need 2 yields for python, stackless requires just 1 Tasklet.yield_() Tasklet.yield_() self.assertEquals([], local._d.keys())
def testJoinAfterExit(self): def child(i): return i ch1 = Tasklet.new(child)(1) ch2 = Tasklet.new(child)(2) Tasklet.yield_() #make sure children are run self.assertEquals(1, Tasklet.join(ch1)) self.assertEquals(2, Tasklet.join(ch2))
def testJoinAfterExit(self): def child(i): return i ch1 = Tasklet.new(child)(1) ch2 = Tasklet.new(child)(2) Tasklet.yield_() #make sure children are run self.assertEquals(1, Tasklet.join(ch1)) self.assertEquals(2, Tasklet.join(ch2))
def loop(self): while True: pkt = self._ch.receive() Tasklet.yield_() if pkt == [1, 2, 3]: # Test request self.dispatcher.receive([4, 5, 6]) elif pkt == ['R', 5, 1, 2, 'V']: # Version request self.dispatcher.receive([ord('R'), 2, 1, ord('V'), 88]) elif pkt == [1, 2, 5]: # Device unreachable (timeout) self.dispatcher.receive([ord('N'), 5, 1]) elif pkt == [1, 2, 6]: # Device unreachable (incorrect response) self.dispatcher.receive([ord('N'), 5, 2]) elif pkt == [1, 2, 7]: # Valid radio response self.dispatcher.receive([ord('R'), 3, 1, 4, 5, 6]) elif pkt == ['R', 5, 1, 2, 'D']: # ADC data request self.dispatcher.receive([ord('R'), 2, 1, ord('D'), 0, 0, 0, 1, 1, 0, 4, 0, 255, 255, 0, 184])
def child(c): for i in range(5): l.append((c, i)) Tasklet.yield_()
def tearDown(self): try: Tasklet.yield_() #this make sure that everything gets a change to exit before we start the next test logging.debug("tearDown %s, tasklet count #%d", self, Tasklet.count()) except: pass
def child(c): for i in range(5): l.append((c, i)) Tasklet.yield_()
def tearDown(self): try: Tasklet.yield_() #this make sure that everything gets a change to exit before we start the next test except: pass
def tearDown(self): try: Tasklet.yield_( ) #this make sure that everything gets a change to exit before we start the next test except: pass
def t(): local.piet = [] for i in range(10): local.piet.append(i) Tasklet.yield_() self.assertEquals(range(10), local.piet)
def tearDown(self): try: Tasklet.yield_() #this make sure that everything gets a change to exit before we start the next test #logging.debug("tearDown %s, tasklet count #%d", self, Tasklet.count()) except Exception: pass
def t(): local.piet = [] for i in range(10): local.piet.append(i) Tasklet.yield_() self.assertEquals(range(10), local.piet)