cat t.py
import threading
import sys
class RecoverKey(threading.Thread):
cond = threading.Condition()
def __init__(self, idx=0):
threading.Thread.__init__(self)
self.idx = idx
def run(self):
for i in range(5):
self.cond.acquire()
print(self.idx * 10)
sys.stdout.flush()
self.idx *= 10
self.cond.release()
if __name__ == '__main__':
for i in range(1, 3):
r = RecoverKey(i)
r.start()
:~/test>python t.py
10
20
100
200
1000
2000
10000
20000
100000
200000
为什么在' 10'之间还有一条线。和' 20'?
有时它可能会消失..