def testQueue(): def printT(): while True: print '+++' yield multitask.sleep(3) def printT2(): while True: print '---' yield multitask.sleep(0.2) def get1(que): while True: print 'xxxx' print(yield que.get()) def put1(que): for x in xrange(0, 10): yield que.put(x) time.sleep(0.5) t = tMultitaskMgr('testQueue') TEST_STOPER(t) t.run() t.add(printT()) t.add(printT2()) que = Queue() t.add(get1(que)) t.add(put1(que)) time.sleep(10) t.stop() print 'over'
def runit(hs=5, ts=5, dbg=1): global hackysackers, turns, debug hackysackers = hs turns = ts debug = dbg hackysacker.counter = 0 circle = [] tm = TaskManager() one = hackysacker('1', circle) tm.add(one.messageLoop()) for i in xrange(2, hackysackers + 1): tm.add(hackysacker(str(i), circle).messageLoop()) one.queue = Queue([one]) tm.run()
def __init__(self, name, circle): self.name = name self.circle = circle circle.append(self) self.queue = Queue()